Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Selecting all radio buttons in a group

Status
Not open for further replies.

tewari68

Programmer
Joined
Jan 25, 2005
Messages
87
Location
US
Hi,
I need some javascript to select all the radio buttons of a group (Select All button). I think some javascript is needed for this, however I am not able to find any javascript for this.
The code is
Code:
<html>
<head>
<script language = javascript>
function populateFields(thisform)
 {
 	
      
  //document.write(document.testing.elements[0].id.checked);
 //for( i = 0; i < document.testing.elements.length; i++ )
 //{
  if(document.testing.delgroup.checked == true)
   {
  
   //document.write(document.testing.elements[0].id);
   for(i=0; i< document.testing.elements[0].value.length; i++)
   {
   //document.write(document.testing.elements[0].value.length);
   //document.write(document.testing.elements[i].value);
   if(document.testing.elements[i].value == document.testing.elements[0].value)
   {
      
        document.testing.elements[i].checked = true;
	}
	}
   }
   else
   document.testing.elements[0].checked = false;
   
   if(document.testing.sendtomegroup.checked == true)
     document.testing.elements[1].checked = true;
     else
     document.testing.elements[1].checked = false;
   
  if(document.testing.spamgroup.checked == true)
     document.testing.elements[2].checked = true;
     else
     document.testing.elements[2].checked = false;     
  
  
    //}
 }
 
</script>
</head>

<Body>
<?
print "<form name=\"testing\" method=\"post\" action=\"radiotestaction.php\" onsubmit=checkval(this.form)>";
echo "<table><tr><th>Delete</th><th>Send To Me</th><th>Report As Spam</th></tr><tr><td><input type = radio name=\"12345\" value=\"del\" id = \"one\"></td><td><input type = radio name=\"12345\" value=\"sendtome\" id=\"two\"></td><td><input type=radio name=\"12345\" value=\"spam\" id=\"three\"></td>";

print "<input type=\"hidden\" name=\"emailarrayname[12345]\" value=\"12345\"></tr>";
print "<input type=\"hidden\" name=\"data\" value=\"\"></tr>";
print "<input type=\"hidden\" name=\"dval\" value=\"\"></tr>";
print "<tr><td><input type = radio name=\"123456\" value=\"del\"></td><td><input type = radio name=\"123456\" value=\"sendtome\"></td><td><input type=radio name=\"123456\" value=\"spam\"></td>";

print "<input type=\"hidden\" name=\"emailarrayname[123456]\" value=\"123456\"></tr>";

print "<tr><td><input type = radio name=\"123457\" value=\"del\"></td><td><input type = radio name=\"123457\" value=\"sendtome\"></td><td><input type=radio name=\"123457\" value=\"spam\"></td>";

print "<input type=\"hidden\" name=\"emailarrayname[123457]\" value=\"123457\"></tr>
<tr><td><input type=\"checkbox\" name=\"delgroup\" value=\"delgroup\" onClick=populateFields(this.form)></td><td><input type=\"checkbox\" name=\"sendtomegroup\" value=\"sendtomegroup\" onClick=populateFields(this.form)></td><td><input type=\"checkbox\" name=\"spamgroup\" value=\"spamgroup\" onClick=populateFields(this.form)></td></tr><tr><td><input type=submit value=submit name=submit></td><td><input style=\"font-size: 10px;\" type=reset name=\"reset\" value=Clear></td></tr></table>";
print "</form>";
?>
</body>
</html>
The name field in the radio buttons property is dynamically generated through query results.
I have written the javascript code populateFields, however it doesn't seem to work.

Appreciate any help in this regards.

Thanks,
Tewari
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top