Jump to content

Checking Radio Buttons


jdubwelch

Recommended Posts

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 radio
for(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]
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]
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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.