Totalmente correcto dukeblass, lo siento, omiti algún campo porque son casi iguales todos, tipo text o select, menos uno tipo radio que es donde falla. Pero no entiendo el porqué!!
Falla en el input "sex" que es de tipo radio, si omito en la funcion javascript "valida_envia(F)" la parte en la que compruebo el campo sex, entonces IE no me recarga la página y funciona correctamente.
Ahora pongo el código completo:
Código Javascript
:
Ver original<script type="text/javascript">
function valida_envia(F){
valid=true;
//valido el nombre
if (F.name.value.length==0){
//alert("Tiene que escribir su nombre");
celda = document.getElementById("input_name");
celda.style.backgroundColor="#ffcc66";
celda.style.border="2px solid #ff0000";
//F.name.focus();
celda2 = document.getElementById("info");
celda2.style.color="#cc0000";
celda2.style.fontWeight="bold";
celda2.style.fontSize="18px";
valid=false;
}
else{
celda = document.getElementById("input_name");
celda.style.backgroundColor="#FFFFCC";
celda.style.border="#FF9933 1px solid";
}
//valido el apellido
if (F.surname.value.length==0){
//alert("Tiene que escribir su apellido");
celda = document.getElementById("input_surname");
celda.style.backgroundColor="#ffcc66";
celda.style.border="2px solid #ff0000";
//F.surname.focus();
valid=false;
}
else{
celda = document.getElementById("input_surname");
celda.style.backgroundColor="#FFFFCC";
celda.style.border="#FF9933 1px solid";
}
//valido el país
if (F.country.value==0){
//alert("Tiene que escribir su país");
celda = document.getElementById("input_country");
celda.style.backgroundColor="#ffcc66";
celda.style.border="2px solid #ff0000";
//F.country.focus();
valid=false;
}
else{
celda = document.getElementById("input_country");
celda.style.backgroundColor="#FFFFCC";
celda.style.border="#FF9933 1px solid";
}
//valido el mes
if (F.BirthMonth.value==0){
celda = document.getElementById("input_month");
celda.style.backgroundColor="#ffcc66";
celda.style.border="2px solid #ff0000";
//F.surname.focus();
valid=false;
}
else{
celda = document.getElementById("input_month");
celda.style.backgroundColor="#FFFFCC";
celda.style.border="#FF9933 1px solid";
}
//valido el dia
if (F.BirthDay.value==0){
//alert("Tiene que escribir su apellido");
celda = document.getElementById("input_day");
celda.style.backgroundColor="#ffcc66";
celda.style.border="2px solid #ff0000";
//F.surname.focus();
valid=false;
}
else{
celda = document.getElementById("input_day");
celda.style.backgroundColor="#FFFFCC";
celda.style.border="#FF9933 1px solid";
}
//valido el año
if (F.BirthYear.value==0){
//alert("Tiene que escribir su apellido");
celda = document.getElementById("input_year");
celda.style.backgroundColor="#ffcc66";
celda.style.border="2px solid #ff0000";
//F.surname.focus();
valid=false;
}
else{
celda = document.getElementById("input_year");
celda.style.backgroundColor="#FFFFCC";
celda.style.border="#FF9933 1px solid";
}
var checksex=0;
celda = document.getElementById("sexm");
if(celda.checked)checksex=1;
celda = document.getElementById("sexf");
if(celda.checked)checksex=1;
if(checksex == 0){
celda = document.getElementById("vpsex");
celda.type="text";
valid=false;
}
else{
celda = document.getElementById("vpsex");
celda.type="hidden";
}
//el formulario se envia
return valid;
}
</script>
Y el formulario:
Código HTML:
<FORM class="formulario" METHOD="POST" ACTION="save.php" onsubmit="return valida_envia(this); " style="text-align:center">
<span id="info">Please fill your details</span>:<br/>
Name: <INPUT TYPE="text" NAME="name" id="input_name"><br/>
Surname: <INPUT TYPE="text" NAME="surname" id="input_surname"><br/>
Gender:
Male <input type="radio" name="sex" value="male" id="sexm">
Female <input type="radio" name="sex" value="female" id="sexf"><br/>
<input type="hidden" style="background-color:#FF3300;color:#FFFFFF;text-align:center;border-radius:10px;-moz-border-radius:10px;-webkit-border-radius:10px;margin-bottom:10px;" value="Gender is a required field!" id="vpsex"/><br/>
Birth date: <select name="BirthMonth" style="width:110px;" id="input_month">
<option value="0">Month</option>
<option value="1">January</option>
</select>
<select name="BirthDay" style="width:70px;" id="input_day">
<option value="0">Day</option>
<?php
for ($i=1; $i<=31; $i++)
{
echo "<option value='$i'>$i</option>";
}
?>
</select>
<select name="BirthYear" style="width:78px;" id="input_year">
<option value="0">Year</option>
<?php
for ($i=2011; $i>=1900; $i=$i-1)
{
echo "<option value='$i'>$i</option>";
}
?>
</select><br/><br/>
Country: <select NAME="country" id="input_country" style="width:267px;">
<option value="0" selected="selected">Select Country</option> <option value="Afghanistan">Afghanistan</option>
<option value="Albania">Albania</option>
<option value="Algeria">Algeria</option>
<option value="Zambia">Zambia</option>
<option value="Zimbabwe">Zimbabwe</option>
</select>
<br/><br/><br/>
<input type="hidden" name="test" />
<input type="submit" value="Next »" name="enviar">
</FORM>