Ciao a tutti!
Ho un form fatto in questo modo:
vorrei che quando il campo di input denominato '2' è vuoto mi apparisse un pop-up con un messaggio di errore.Codice PHP:
<form method='post' name='cart' action=index.jsp?title=&author=&order=titleDesc onsubmit="return checkform(this);">
<table class='paginated' cellspacing='0' cellpadding='0'>
...
<tr>
<th><input type='checkbox' name='books' value='2'/></th>
<td>[i]Trainspotting[/i]</td>
<td>Irvine Welsh</td>
<td>W. W. Norton & Company</td>
<td align='center'>978-0393314809</td>
<td align='center'>1996</td>
<td align='left' class='price'>$ 11.16</td>
<td><input type=text name='2' size=1 value=1>
</tr>
<tr>
<th><input type='checkbox' name='books' value='3'/></th>
<td>[i]Lords of Chaos: The Bloody Rise of the Satanic Metal Underground[/i]</td>
<td>Michael Moynihan & Didrik Soderlind</td>
<td>Feral House</td>
<td align='center'>978-0922915941</td>
<td align='center'>2003</td>
<td align='left' class='price'>$ 12.89</td>
<td><input type=text name='3' size=1 value=1>
</tr>
...
</table>
<input type=submit name="update" value='Update Cart'></p>
Allora ho fatto questa funzione:
Premetto che controlli di questo tipo ne ho fatti una miriade ed hanno sempre funzionato, ma questa volta no.Codice PHP:
function checkform (form){
...
if (form.2.value == ""){
alert("Controlla la quantità.");
form.2.focus();
return false ;
}
...
}
E' per caso dovuto al fatto che chiamo un campo di input con un numero?
Grazie.