Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Jul 2004
    Posts
    17
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Help with passing variable into a javascript function from asp.Net

    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

  • #2
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,043
    Thanks
    0
    Thanked 251 Times in 247 Posts
    Code:
    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


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •