View Full Version : form element id question

06-17-2008, 01:09 AM
I have a form element that is a radio and mutually exclusive of 4 others. All 4 have the name 'radio'. I am using JS to calculate the value of the selected radio as well as other elements on the form.

When the form is submitted I need to know which one of the 4 radios was selected so that I can insert the proper info into a database. Since they all have the same name to allow them to be mutually exclusive the post just has the one name. I have been comparing the value 'radio' with the value of other variables on the page to determine which of the four was selected.

This works great until I have radios with the same values. Is there another way to identify radios while still leaving them mutually exclusive?

06-17-2008, 01:57 AM
I just solved my own question but wanted to post it if anyone else has a similar need:

I left the radio button name alone and simply made a hidden input type and used JS onblur at each radio button to enter a distict value that can be retrieved on the post.

Philip M
06-17-2008, 08:20 AM
An example of radio button polling to check which one has been selected:-

(buttons have same name, different values)

<form name = "myform">
1<input type = "radio" name = "rad1" value = "1">
2<input type = "radio" name = "rad1" value = "2">
3<input type = "radio" name = "rad1" value = "3">
4<input type = "radio" name = "rad1" value = "4">
<input type = "button" value = "Click here to rotate the selected image" onclick = "rotate()">

<<script type = "text/javascript">
function rotate() {
for (var i =0; i < document.myform.rad1.length; i++) {
if (document.myform.rad1[i].checked) {
var selected = document.myform.rad1[i].value;
if (!selected) {
alert ("You must select an image to rotate! ");
return false;

All advice is supplied packaged by intellectual weight, and not by volume. Contents may settle slightly in transit.