JQuery problem with radio buttons

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
User avatar
Sindarin
Forum Regular
Posts: 521
Joined: Tue Sep 25, 2007 8:36 am
Location: Greece

JQuery problem with radio buttons

Post by Sindarin »

I have a radio group,

Code: Select all

<input id="row_jquery_src0" name="row_jquery_src" type="radio" value="0" class="radio" />option1
<input id="row_jquery_src1" name="row_jquery_src" type="radio" value="1" class="radio" />option2
how can I get the the selected value in order to submit it in my database?

I tried var row_jquery_src = $("#row_jquery_src").attr("value"); and it doesn't work, it returns undefined.
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Re: JQuery problem with radio buttons

Post by josh »

Try

$("#row_jquery_src").val()
or
$("#row_jquery_src:selected").val()

But I think the id will not work since it is unique
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: JQuery problem with radio buttons

Post by pickle »

Code: Select all

$("input[name=row_jquery_src]").val()
Assuming you're using 1.3.2. If you're using 1.2.6, put an @ in front of name.

You might also need the :selected modifier ~josh mentioned, but I'd try it without first.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
User avatar
Sindarin
Forum Regular
Posts: 521
Joined: Tue Sep 25, 2007 8:36 am
Location: Greece

Re: JQuery problem with radio buttons

Post by Sindarin »

Thanks guys, I had to use "checked" instead of "selected", so it is:

Code: Select all

$("input[name=row_jquery_src]:checked").val();
or

Code: Select all

$("input[name=row_jquery_src]:checked").attr("value");
Post Reply