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