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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

radio button don't work properly

Status
Not open for further replies.

786snow

Programmer
Nov 12, 2006
75
what is wrong with the code here, no matter what radio button I pick, even if I don't pick any I get the value "by_date"




Code:
<script>
function submitRequest() {
    
   var test=document.getElementById('dateType').value;
   alert(test); }
  </script>


<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>New Page 3</title>
</head>

<body>
	<FORM ACTION="/NASApp/EDocsCtx/EDocsServlet?actionType=2" METHOD="POST" NAME= "Statements"  onsubmit="return submitRequest()">
<table width="70%" border="0" cellspacing="5" cellpadding="0">
  					<tr>
						<td width="20"></td>
						<td align="right" nowrap><input type="radio" name="dateType"  id="dateType"  value="by_date" ><b>Date:</b></input></td>
					  	<td align="right" nowrap><input type="radio" name="dateType"  id="dateType" value="date_range"><b>Date Range:</b></input></td>
						
	 					<td align="left"> <input name="edocsStatements" type="image"  ALT="Search"   SRC="/images/b_Search.gif"  BORDER="0" HEIGHT="21" WIDTH="68" /></td> 
  					</tr> 

</table>

</body>

</html>
 
You have to loop through the collection of radio buttons and find the one that's checked. Like this:
Code:
<script>
function submitRequest() {
   var test = document.getElementById('dateType');
   for (i = 0; i < test.length; i++) {
      if (test[i].checked) {
         alert(test[i].value);
      }
   }
}
</script>

-kaht

Looking for a puppy? [small](Silky Terriers are hypoallergenic dogs that make great indoor pets due to their lack of shedding and small size)[/small]
 
thanks for the code ...good point I forgot to create an array all you need is the name to be same, not the id ........
 
Good point Cory, I went into auto-reply mode and didn't even notice what I was doing [banghead]

Change the getElementById to this:
Code:
var test = document.forms["Statements"].elements["dateType"];

-kaht

Looking for a puppy? [small](Silky Terriers are hypoallergenic dogs that make great indoor pets due to their lack of shedding and small size)[/small]
 
headbang.gif




*cLFlaVA
----------------------------
[tt]"quote goes here"[/tt]
[URL unfurl="true"]http://www.coryarthus.com/[/url]
 
Where you have:

<input type="radio" name="dateType" id="dateType" value="by_date" ><b>Date:</b></input></td>
<td align="right" nowrap><input type="radio" name="dateType" id="dateType" value="date_range"><b>Date Range:</b></input>

It should be:

Code:
   <input type='radio' name='dateType' id='dateTypeSingle'
          value='by_date' />
   <label for='dateTypeSingle'><b>Date:</b></label>

   <input type='radio' name='dataType' id='dateTypeRange'
          value='date_range' />
   <label for='dateTypeRange'><b>Date Range:</b></label>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top