Failed to set href inside jQuery click event

Hi I am trying to set the href using JQuery inside the RadioButtonList click event but it doesn't work. If I take the same code for the document.ready event it works fine, but not on the click event. Please advice.
$(document).ready(function() {    
   url = "Results.aspx?latitude=" +latitude + "&Longitude=" + longitude;

 $("a[href='http://www.google.com/']").attr("href", url); // this works..
        }        
        $('.rbl input').click(function() {

            id = $(this).parent().children("input").val();
            url = "Results.aspx?latitude=" + latitude + "&Longitude=" + longitude + "&ServiceCenterProductTypeId=" + id;
            //alert(url);
            $("a[href='http://www.google.com/']").attr("href", url); //this doesnt work....

        });
    });

      

+2


a source to share


2 answers


You (possibly) have a property set AutoPostBack

to true, which causes a postback to the server, which reloads the entire page.



Hence your changes in Javascript will be overwritten by writeback.

0


a source


It looks like you have an extra closing curly brace after this line }

:



$("a[href='http://www.google.com/']").attr("href", url); // this works..

      

+4


a source







All Articles