![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
|
Hi, I would like to run a jvascript, checking if the radio button is checked. My radio button looks like: input type="radio" name="owned_business" value="yes" and i would like to check it with this: * * * * alert (document.myform.owned_business.checked); * * * * if (document.myform.owned_business.checked == false) but alert returns me "undefined" and i don't understand why, my form name is "myform" and the name of the radio is "owned_business" so i'm not seeing where i go wrong. Can anyone help me? |
#2
| |||
| |||
|
|
nolo contendere wrote: On Jan 2, 2:09*pm, Ron Eggler <NORE... (AT) example (DOT) com> wrote: Hi, I would like to run a jvascript, checking if the radio button is checked. My radio button looks like: input type="radio" name="owned_business" value="yes" and i would like to check it with this: alert (document.myform.owned_business.checked); if (document.myform.owned_business.checked == false) but alert returns me "undefined" and i don't understand why, my form name is "myform" and the name of the radio is "owned_business" so i'm not seeing where i go wrong. Can anyone help me? There's something weird with Radio buttons. I believe you need to iterate through the set, instead of grabbing the checked one. Try something like this: function get_checked_radio( radio, form ) { * for ( var i = 0; i < form.length; i++ ) { * * var e = form.elements[i]; * * var ename = e.name; * * if ( ename != radio ) continue; * * if ( e.checked ) return e.value; * } * return ""; } But why can't i just simply check the elemet's property? Seems simpler to me. |
![]() |
| Thread Tools | |
| Display Modes | |
| |