php_novice2007 Posted August 17, 2007 Share Posted August 17, 2007 Hi, I have the following code: <table><tr> <td><input type=radio name="AnimationChoice" checked value="u0001">u0001</td> <td><input type=radio name="AnimationChoice" checked value="u0002">u0002</td> <td><input type=radio name="AnimationChoice" checked value="u0015">u0015</td> </tr></table> <input id="animatePath" type="button" onclick="startAnimation();" value="Animate Path!"> function startAnimation(){ var r = document.getElementById("AnimationChoice"); var counter; for (counter = 0; counter < r.length; counter++) { if (r[counter].checked) { alert(r[counter].value); break; } } document.getElementById("animatePath").style.display = 'none'; animatePath(r[counter].value); } First I want to find out which radio button is selected. In FF I'm getting the error which says "r has no properties", and in IE I don't get any error at all, but no alert box either Can anyone help? Thanks in advance~! Link to comment https://forums.phpfreaks.com/topic/65350-radio-buttons/ Share on other sites More sharing options...
adam84 Posted August 17, 2007 Share Posted August 17, 2007 1. try this to check if your radio button is selected var r = document.getElementById("AnimationChoice"); var counter; for (counter = 0; counter < r.options.length; counter++) { if (r.options[counter].selected ) { alert(r.options[counter].value); break; } } 2. Something I found by putting id instead of name, it solved the problem. No 100% sure, try it <td><input type=radio id="AnimationChoice" checked value="u0001">u0001</td> <td><input type=radio id="AnimationChoice" checked value="u0002">u0002</td> <td><input type=radio id="AnimationChoice" checked value="u0015">u0015</td> Link to comment https://forums.phpfreaks.com/topic/65350-radio-buttons/#findComment-326397 Share on other sites More sharing options...
php_novice2007 Posted August 18, 2007 Author Share Posted August 18, 2007 This doesn't work It says option.0 is null or not an object. Link to comment https://forums.phpfreaks.com/topic/65350-radio-buttons/#findComment-327390 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.