...

View Full Version : Help with passing variable into a javascript function from asp.Net



Bob Burns
07-16-2004, 05:49 PM
Hi,
I am dynamically creating a table that contains links and images in my asp.net code as follows

sub page_load(sender, event_args)
{
Dim record_set As System.Data.SqlClient.SqlDataReader
record_set = command.ExecuteReader
Dim strBuilder As System.Text.StringBuilder

strBuilder.Append("<Table cellspacing= cellpadding>")
strBuilder.Append("<tr><td>")
strBuilder.Append("<a href= ' "& record_set.GetString("URL_LOCATION") &" ' onmouse = 'changeLinkColor( "& strLinkID&" )' id =' hello_name '>")

strBuilder.Append(" Google ")
strBuilder.Append("</a>")

literal_html_component_accessible_in_asp.InnerHtml = strBuilder.ToString()


}//end of page_load


my javascript code is
<script language="Javascript">

function changeLinkColor(link_ID)
{
document.getElementByID(link_ID).style.Color="ffff00"

}//end of function
</script>

for some bizzare reason when I pass in the argument link_ID into the javascript function is value isn't what its supposed to be, can anyone spot something wrong with my code syntax??
Thanks Bob

glenngv
07-19-2004, 08:03 AM
strBuilder.Append("<a href=""")
strBuilder.Append(record_set.GetString("URL_LOCATION"))
strBuilder.Append(""" onmouseover=""changeLinkColor('")
strBuilder.Append(strLinkID)
strBuilder.Append("')"">Google</a>")
...
<script language="Javascript">
function changeLinkColor(link_ID)
{
document.getElementById(link_ID).style.color="ffff00"
}//end of function
</script>

But why not use pure CSS? http://www.w3schools.com/css/css_pseudo_classes.asp



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum