Page 1 of 1

JQuery problem with radio buttons

Posted: Thu Dec 17, 2009 7:03 am
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.

Re: JQuery problem with radio buttons

Posted: Thu Dec 17, 2009 8:18 am
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

Re: JQuery problem with radio buttons

Posted: Thu Dec 17, 2009 10:34 am
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.

Re: JQuery problem with radio buttons

Posted: Fri Dec 18, 2009 8:56 am
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");