Jump to content

radio buttons


php_novice2007

Recommended Posts

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

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

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.