jdubwelch Posted December 14, 2006 Share Posted December 14, 2006 Okay... I have this set of 4 different radio buttons. Each column is a set. I want an error message to pop up when someone tries to select 2 radio buttons in the same row. Is that possible?[img]http://www.jwelchdesign.com/images/fourth.gif[/img] Link to comment https://forums.phpfreaks.com/topic/30603-checking-radio-buttons/ Share on other sites More sharing options...
artacus Posted December 14, 2006 Share Posted December 14, 2006 Give each column the same value 1,2,3,4[code]function checkRadio() {var status = new Array();var radObj = document.getElementsByTagName('INPUT'); //actuall gets all input elements not just radiofor(var i=0; i<radObj.length; i++) { if(radObj[i].type == 'radio' && radObj[i].checked) { var colNum = radObj[i].value; if(status[colNum]) { alert('You cant select 2 in the same column'); return false; } else { status[colNum] = 1; } }}}[/code] Link to comment https://forums.phpfreaks.com/topic/30603-checking-radio-buttons/#findComment-140997 Share on other sites More sharing options...
jdubwelch Posted December 16, 2006 Author Share Posted December 16, 2006 so, i would call that function on each radio button like this?[code]<td width=\"27\" class=\"fourth\"><input name=\"F1\" type=\"radio\" value=\"$row[bowl_name]\" onChange=(checkRadio(1)) $F1selected /></td><td width=\"27\" class=\"fourth\"><input name=\"F2\" type=\"radio\" value=\"$row[bowl_name]\" onChange=(checkRadio(2))$F2selected /></td><td width=\"27\" class=\"fourth\"><input name=\"F3\" type=\"radio\" value=\"$row[bowl_name]\" onChange=(checkRadio(3))$F3selected /></td><td width=\"27\" class=\"fourth\"><input name=\"F4\" type=\"radio\" value=\"$row[bowl_name]\" onChange=(checkRadio(4))$F4selected /></td>[/code] Link to comment https://forums.phpfreaks.com/topic/30603-checking-radio-buttons/#findComment-142204 Share on other sites More sharing options...
artacus Posted December 17, 2006 Share Posted December 17, 2006 The function I wrote doesn't take any arguments. But you could probably just do it onSubmit(). Otherwise say user wants to select col 3 on row 2, if you check w/ onChange() it will throw an error because 3 is already selected in row 3. Otherwise you'd have to write a better function that unchecked 3 in row 3. Link to comment https://forums.phpfreaks.com/topic/30603-checking-radio-buttons/#findComment-142671 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.