Click to See Complete Forum and Search --> : swap logo img based on field value stored in variable


wpc458
07-11-2005, 04:36 PM
I wish to change a logo in a table cell based upon male/female value in a table field. Men see one logo, women another, children a third. Does anyone have any examples to do this?

buntine
07-11-2005, 04:49 PM
Just a basic If statement or Select Case statement can acheive something like this. I will presume you have your recordSet object created and opened so as to stay within context.

<%
Dim strImagefile

Select Case UCase(rs("sex"))
Case "M"
strImageFile = "male.gif"
Case "F"
strImageFile = "female.gif"
Case "C"
strImageFile = "child.gif"
End Select

Response.Write "<img src=""" & strImageFile & """ alt=""Logo"" />"
%>

Alternativly, you could possibly just calculate the correct file name based on the value in the table. For example, you could have three images "M.gif", "F.gif", "C.gif" and do something like this:

Dim strImageFile: strImageFile = rs("sex") & ".gif"

Regards.

wpc458
07-11-2005, 04:52 PM
you are correct I have already obtained the RS value actually stored in a variable.

Thus to dynamically change the TD do I use an ID in the TD tag and reference within the case select? how would I code the dynamic swap within the TD tag?

buntine
07-11-2005, 04:57 PM
I'm not sure I follow... The HTML is just seen as plain text to ASP, the two technologies cannot really communicate.

All you need to do is use a logic gate (such as the Select Case I posted) to determine which HTML code to generate.

Regards.

wpc458
07-11-2005, 05:02 PM
well I was thinking that I need to reference a specific cell location that contains an image. The page displays with a default image, after loggin in then I wish to swap to another image based on sex. Currently the TD tag does not have an id= param....I was thinking it might need one for me to refer to it specifically after initial page loading. I hope that makes thing a little clearer.

buntine
07-11-2005, 05:57 PM
Ok. I understand what your saying. But you need to acknowledge that setting a parameter on an HTML element means nothing to ASP. The ASP code will be executed and forgotten about before the HTML is even rendered.

The ASP code will need to be embedded into the HTML document in the location you want the image to be displayed.

Regards.