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]
Link to comment
Share on other sites

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.