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

No value for radio button

Status
Not open for further replies.

beco73

Programmer
May 8, 2005
157
CA
Hi,

I don't know why i don't get any value for radio buton. I get 'undefined' in the alert. i was wondering do you see anything wrong with the code?

thanks

****************


<tr>

<td><input type='radio' name='buyrent' value='0' checked >&nbsp;<strong>Buy</strong>
</td>

<td><input type='radio' name='buyrent' value='1' >&nbsp;<strong>Rent</strong>
</td>

</tr>

<script language="JavaScript" type="text/javascript">
function validate()
{
h=document.search.buyrent.value;
alert(h);
}
</script>
 
yes - multiple elements that share a name (such as radios) are referenced using array notation, so you have to do something like
Code:
<script language="JavaScript" type="text/javascript">
function validate()
{
 if (document.search.buyrent[0].checked) {
  h = document.search.buyrent[0].value;
  alert(h);
 }
}
</script>

-jeff
try { succeed(); } catch(E) { tryAgain(); } finally { rtfm(); }
i like your sleeves...they're real big
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top