leora
leora

Reputation: 196489

why isn't this Jquery readingthe correct radio button checked value?

i have the following code in an asp.net-mvc view:

<input checked="checked" id="outputFilter" name="outputFilter" value="Detail" type="radio"> Detail Info
<input id="outputFilter" name="outputFilter" value="Summary" type="radio"> Summary Info

<input checked="checked" id="outputSorting" name="outputSorting" value="Milestone" type="radio"> Milestone
<input id="outputSorting" name="outputSorting" value="AppRank" type="radio">App --&gt; Rank

and i have this javascript code:

 var sortValue = $("input[@name='outputSorting']:checked").val();
 var dataValue = $("input[@name='outputFilter']:checked").val();

the issue is that i get the value "Detail" for BOTH sortValue and dataValue

can anyone see anything wrong with this code that would lead this to be the case??

Upvotes: 2

Views: 177

Answers (3)

Andy
Andy

Reputation: 30135

Also, IDs have to be unique. Use classes instead

Upvotes: -1

rcravens
rcravens

Reputation: 8390

Try removing the '@' symbol. Hope this helps.

Bob

Upvotes: 1

Anurag
Anurag

Reputation: 141879

Remove the @ sign. That has been deprecated long ago for attributes.

var sortValue = $("input[name='outputSorting']:checked").val();
var dataValue = $("input[name='outputFilter']:checked").val();

Also, close your input tags to make the HTML valid.

<input ... value="Detail" type="radio" /> Detail Info
<input id="outputFilter" ... type="radio" /> Summary Info
...

Upvotes: 4

Related Questions