Ver Mensaje Individual
  #1 (permalink)  
Antiguo 21/11/2013, 09:35
Avatar de adryan310
adryan310
 
Fecha de Ingreso: septiembre-2012
Mensajes: 450
Antigüedad: 11 años, 8 meses
Puntos: 3
Pregunta Como capturar el value de un radio button en javascript?

Hola a todos,

Tengo esto en mi javascript:
Cita:
function validate(){
var typeSearch = document.frmSearch.optionsSuccess.value; // Lo hice así primeramente.
var typeSearch = document.getElementsByName('optionsSuccess'); // Luego así también y tampoco funciono.
var radio = typeSearch .value;

if(typeSearch == 'Y' || typeSearch == 'N' || typeSearch =='B'){
alert('Exito!');
}else{
alert('Error!');
}

if(radio == 'Y' || radio == 'N' || radio == 'B'){
alert('Funciono la segunda opcion!');
}else{
alert('Error en segunda opcion tambien!');
}

}
Estos son los radios buttons:
Código HTML:
<form id="frmSearch" name="frmSearch" method="post">
  <input type="radio" checked="true" name="optionsSuccess" value="Y">
  <input type="radio" name="optionsSuccess" value="N">
  <input type="radio" name="optionsSuccess" value="B">
  <input type="submit" id="Search" name="Search" value="Search" onclick="return validate()"/>
</form> 
Pero al parecer mi javascript no me esta capturando los valores de los radios trate con esas dos opciones pero ninguna me funciona, alguna ayuda ?