Cita:
Iniciado por Pantaláimon
Cierto, los innerHTML cambian (que por cierto, si sólo quieres añadir texto usa mejor textContent ). Pero vaya, la idea es la misma, poner la información que cambia en un objeto o array y recorrer la estructura que se repite mediante un bucle:
Código Javascript
:
Ver originalvar info = {
name : ['namebox' , 'Please fill in name' ],
passport : ['passportbox' , 'Please fill in your identification' ],
emailtrue : ['emailtruebox' , 'Please fill in email' ],
repeat_email: ['repeat_emailbox', 'Please repeat email' ],
telmobile : ['telmobilebox' , 'Please fill in mobile to bring on holiday' ],
test : ['resultbooking' , 'Please answer the security question' ]
}
for( key in inputs ) {
if(document.Booking[key].value == '')
{
divresult = document.getElementById(info[key][0])
divresult.className = 'validation'
divresult.textContent = info[key][1];
document.Booking[key].focus();
return false;
}
}
preventDefault es un método de javascript. Aquí dejo información;
http://www.w3.org/TR/2003/NOTE-DOM-L...t-binding.html http://www.lewebmonster.com/funcion-...en-javascript/ https://developer.mozilla.org/es/doc...preventDefault
La idea básica es que el handler( función llamada cuando ocurre el evento) acepta un parámetro event y este puede llamar al método preventDefault para evitar el submit:
Código Javascript
:
Ver originalfunction OnSubmitBooking( event ) {
event.preventDefault();
if( error validacion ) {
// ...
} else { // si todo correcto
// hacer lo que sea
// ...
// hacer submit al formulario
this.submit();
}
}
Aunque sin saber del HTML quizá esté dando palos de ciego.
Un saludo!
Gracias, a la tarde lo pruebo,
en un tonto intento intenté esto por si acaso...
pero no iba lol
divresult.innerHTML = 'Please fill in name','Please','Please2','Please3','Please4','Plea se5';
si sé html, css, php y mysql, pero los arrays es mi lado debil, será porque soy autodidacta, tan solo uso php mas bien para sacar datos de la base de datos y me acabo de iniciar en javascript y ajax, antes lo usaba pero solo modificaba, hacerlo tu ya es otra cosa.
Gracias de nuevo