PDA

View Full Version : crazy radio buttons


cutovoi
07-08-2004, 08:27 AM
Hi for all

I created the 4 radios and no one send their value. When I show the value, appears undefined instead of radio button's value.
Here is a part of the code:

<tr>
<td><input type="submit" value="caminho" onClick="abre(buscador.value)">
<input type="submit" value="colar" onClick="excel()"></td>
<td><input type=radio name=buscador value=altavista>Altavista</td>
</tr>
<tr>
<td></td><td><input type=radio name=buscador value=yahoo>Yahoo</td>
</tr>
<tr>
<td></td><td><input type=radio name=buscador value=cade>Cadê</td>

Can anyone helps me?

Tks

agent002
07-08-2004, 08:32 AM
Hi Cutovoi, and welcome to HTMLForums! :)
Getting the selected value of a radio group is a bit tricky... but here is a function for doing that. Put this code between the <head> and </head> tags:
<script type="text/javascript">
//<![CDATA[

function getRadio(radioName){
var radios = document.getElementsByName(radioName);
for(var i = 0; i < radios.length; i++){
if(radios[i].checked) return radios[i].value;
}
return null;
}

//]]>
</script>
Then, to get the value of a radio group, call the function with the name of buttons in the argument, for instance:
onclick="alert(getRadio('radioGroupName'));"