Tengo un problema con la comprobación de la entrada. No quiero enviar la solicitud si la longitud de la entrada es inferior a 3.
Mi formulario:
<form method='post' action=''>
Albūma nosaukums: # # this is the input --><input id='titleeee' type='text' name'album_title' /><br />
Bilde Nr 1: <input type='file' name='pic_nr1' /><br />
Bilde Nr 2: <input type='file' name='pic_nr2' /><br />
Bilde Nr 3: <input type='file' name='pic_nr2' /><br />
Aktīvs*:
<select>
<option>Jā</option>
<option>Nē</option>
</select>
<br />
<input Onclick='testlenght(document.getElementById("titleeee"), "Tavs albūma nosaukums ir pa īsu!", "3")' type='submit' value='Pievienot' />
</form>
Puedes añadir un manejador de formulario onsubmit, algo como:
<form onsubmit="return validate();">
</form>
<script>function validate() {
// check if input is bigger than 3
var value = document.getElementById('titleeee').value;
if (value.length < 3) {
return false; // keep form from submitting
}
// else form is good let it submit, of course you will
// probably want to alert the user WHAT went wrong.
return true;
}</script>