views:

44

answers:

4

So if this qstring var is set then i need to check a certain radio button

ive tried the following :

$("#AcctRB").attr('checked', 'checked');
$('input[id=AcctRB]:eq(1)').attr('checked', 'checked');

which does not work. I might have a syntax error

Here is the rb :

<input type="radio" onclick="accountShow()" id="AcctRB" runat="server" name="GuestAndAccountRB" enableviewstate="true" />Account


 <% If Request.QueryString("login") = "guest" Then%> 
                 <script type= "text/javascript">
                     $(".new-accnt-ad").show("slow");
                     $(".accountPanel").hide("slow");
                     $(".guestPanel").show("slow");
                     $("#AcctRB").attr('checked', 'checked');
                 </script>
                 <%Else%>
              <script type= "text/javascript">
                  $(".new-accnt-ad").hide("slow");
                  $(".accountPanel").show("slow");
                  $(".guestPanel").hide("slow");
                  $('input[id=AcctRB]:eq(1)').attr('checked', 'checked');
              </script>

                 <% End If %>

This simply does not check the radio button in either case ive tried.

+1  A: 
$('input[id=AcctRB]:eq(1)').attr('checked', true);
Avien
right i've tried that and doesnt seem to work
While this is "better", it should work fine with _"checked"_ as the attr value.
Squeegy
+1  A: 

I would bet that your selectors are not returning any elements, because that should work. Although it's probably cleaner to set checked to true in attr().

Proof this works: http://jsfiddle.net/A7Bke/

Squeegy
A: 

The JS might run before all the elements are created. Check out: $(document).ready():

$(document).ready(function() {
   // put all your jQuery goodness in here.
});

It's also not necessary to do this with JavaScript; simply add it to the HTML directly, depending on the QueryString("login").

Alec
hmm can you please demonstrate?
`<input <% If Request.QueryString("login") == "guest" %> checked="checked" <% End If %> />`
Alec
A: 

I agree with Squeegy. I had the same problem the other day, and the issue was that even though the selector seemed to be correct, it was not retrieving any results.

I recommend getting a more advanced browser toolkit such as the FireBug plugin for Firefox or using Chrome's Developer tools. Try your jQuery selectors out in the Console Window they provide, and see if the results are what you expect. These tools also allow you to place breakpoints in your JavaScript code to see if the selector is being called by the browser.

Update: To test out jQuery selectors in Firebug, enable the Console tab, then simply type out the selector. The console will respond back with those elements that were selected by the jQuery call.

David Ipsen
I have firebug, but i dont see where i can test my jquery