Discussion:
[Dojo-interest] get radio button's value
Jean-Rubin Leonard
2010-03-05 01:12:36 UTC
Permalink
Hi all,
I have the following in my template:

<div class="radio_lump"><input type="radio" dojoAttachPoint="lumpSumOnce"
dojoType="dijit.form.RadioButton" name="lump_sum_frequency"
id="lumpSumOnce" value="once" />Once</div>
<div class="radio_lump"><input type="radio"
dojoAttachPoint="lumpSumRecurrent" dojoType="dijit.form.RadioButton"
name="lump_sum_frequency" id="lumpSumRecurrent" value="recurring" />Over
several periods</div>

I want to know which of the button is selected. Is there a way I can do that
without going through each button and checking if they have a set value? I
hope there's a way to do this because what would one do if one has like 5
buttons? I was thinking of doing this.lump_sum_frequency but that's the name
not the attachpoint and it's therefore invalid in the js.

Any advice is welcome.

Thanks,
JR
Viswanath V Rao
2010-03-05 03:53:11 UTC
Permalink
I have a radio button sample, where i loop thru all radio buttons of a
particular group and find "selected" attribute to identify.

code snippet as follows:

if (elem.type == "radio" && elem.name == "division")
if (elem.checked) {
s = "Yr Division :"+elem.value;
break;
}
Post by Jean-Rubin Leonard
Hi all,
<div class="radio_lump"><input type="radio" dojoAttachPoint="lumpSumOnce"
dojoType="dijit.form.RadioButton" name="lump_sum_frequency"
id="lumpSumOnce" value="once" />Once</div>
<div class="radio_lump"><input type="radio"
dojoAttachPoint="lumpSumRecurrent" dojoType="dijit.form.RadioButton"
name="lump_sum_frequency" id="lumpSumRecurrent" value="recurring" />Over
several periods</div>
I want to know which of the button is selected. Is there a way I can do
that without going through each button and checking if they have a set
value? I hope there's a way to do this because what would one do if one has
like 5 buttons? I was thinking of doing this.lump_sum_frequency but that's
the name not the attachpoint and it's therefore invalid in the js.
Any advice is welcome.
Thanks,
JR
_______________________________________________
FAQ: http://dojotoolkit.org/support/faq
Book: http://docs.dojocampus.org
http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest
Lokesh Madan
2010-03-05 04:03:11 UTC
Permalink
try something like this:


var checkedButtons =
dojo.query('[name=lump_sum_frequency]').filter(function(radio){return
radio.checked;});
Post by Viswanath V Rao
I have a radio button sample, where i loop thru all radio buttons of a
particular group and find "selected" attribute to identify.
if (elem.type == "radio" && elem.name == "division")
if (elem.checked) {
s = "Yr Division :"+elem.value;
break;
}
Post by Jean-Rubin Leonard
Hi all,
<div class="radio_lump"><input type="radio"
dojoAttachPoint="lumpSumOnce" dojoType="dijit.form.RadioButton"
name="lump_sum_frequency" id="lumpSumOnce" value="once" />Once</div>
<div class="radio_lump"><input type="radio"
dojoAttachPoint="lumpSumRecurrent" dojoType="dijit.form.RadioButton"
name="lump_sum_frequency" id="lumpSumRecurrent" value="recurring" />Over
several periods</div>
I want to know which of the button is selected. Is there a way I can do
that without going through each button and checking if they have a set
value? I hope there's a way to do this because what would one do if one has
like 5 buttons? I was thinking of doing this.lump_sum_frequency but that's
the name not the attachpoint and it's therefore invalid in the js.
Any advice is welcome.
Thanks,
JR
_______________________________________________
FAQ: http://dojotoolkit.org/support/faq
Book: http://docs.dojocampus.org
http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest
_______________________________________________
FAQ: http://dojotoolkit.org/support/faq
Book: http://docs.dojocampus.org
http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest
--
Regards,
Lokesh Madan

An hour of your time,
HOPE FOR A LIFETIME.
http://www.workanhour.org
Ben Hockey
2010-03-05 14:18:13 UTC
Permalink
hi jr,

if your radio buttons are in a dijit.form.Form then
form.attr('value').lump_sum_frequency should be the value of the radio
button which is selected. for an example, look at this http://download.dojotoolkit.org/release-1.4.0/dojo-release-1.4.0/dijit/tests/form/Form.html
and click the button which says "Get values from form!" and look at
the console. r2 is the radio button.

ben...
Post by Jean-Rubin Leonard
Hi all,
<div class="radio_lump"><input type="radio"
dojoAttachPoint="lumpSumOnce" dojoType="dijit.form.RadioButton"
name="lump_sum_frequency" id="lumpSumOnce" value="once" />Once</div>
<div class="radio_lump"><input type="radio"
dojoAttachPoint="lumpSumRecurrent"
dojoType="dijit.form.RadioButton" name="lump_sum_frequency"
id="lumpSumRecurrent" value="recurring" />Over several periods</div>
I want to know which of the button is selected. Is there a way I can
do that without going through each button and checking if they have
a set value? I hope there's a way to do this because what would one
do if one has like 5 buttons? I was thinking of doing
this.lump_sum_frequency but that's the name not the attachpoint and
it's therefore invalid in the js.
Any advice is welcome.
Thanks,
JR
_______________________________________________
FAQ: http://dojotoolkit.org/support/faq
Book: http://docs.dojocampus.org
http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest
Jean-Rubin Leonard
2010-03-05 22:41:31 UTC
Permalink
Hey Ben,
My radio are in a form but not directly. In that specific case they are in a
widget that is contained in a form. It's in that widget's _getValueAttr that
I need to access which radio is selected as I will return different stuff in
different cases. I have created a ticket (#10819) that would allow each
radio node to return the group value, meaning the value of the selected
radio and null if none is selected. This way the widget is more independant
from the form.

Thanks for the feedback,
JR
Post by Ben Hockey
hi jr,
if your radio buttons are in a dijit.form.Form then
form.attr('value').lump_sum_frequency should be the value of the radio
button which is selected. for an example, look at this
http://download.dojotoolkit.org/release-1.4.0/dojo-release-1.4.0/dijit/tests/form/Form.html
and click the button which says "Get values from form!" and look at
the console. r2 is the radio button.
ben...
Post by Jean-Rubin Leonard
Hi all,
<div class="radio_lump"><input type="radio"
dojoAttachPoint="lumpSumOnce" dojoType="dijit.form.RadioButton"
name="lump_sum_frequency" id="lumpSumOnce" value="once" />Once</div>
<div class="radio_lump"><input type="radio"
dojoAttachPoint="lumpSumRecurrent"
dojoType="dijit.form.RadioButton" name="lump_sum_frequency"
id="lumpSumRecurrent" value="recurring" />Over several periods</div>
I want to know which of the button is selected. Is there a way I can
do that without going through each button and checking if they have
a set value? I hope there's a way to do this because what would one
do if one has like 5 buttons? I was thinking of doing
this.lump_sum_frequency but that's the name not the attachpoint and
it's therefore invalid in the js.
Any advice is welcome.
Thanks,
JR
_______________________________________________
FAQ: http://dojotoolkit.org/support/faq
Book: http://docs.dojocampus.org
http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest
_______________________________________________
FAQ: http://dojotoolkit.org/support/faq
Book: http://docs.dojocampus.org
http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest
Continue reading on narkive:
Loading...