HighDots Forums  

focus sui campi

Javascript (Italian) Il linguaggio JavaScript (it.comp.lang.javascript)


Discuss focus sui campi in the Javascript (Italian) forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Maurizio Gallo
 
Posts: n/a

Default focus sui campi - 09-10-2003 , 11:49 AM






Il codice che allego è di una funzione che controlla se i campi di un form
sono vuoti o meno

function chkcampi(NomeCampi)
/* Funzione che verifica l'inserimento di valori nei campi
Metodo di chiamata : chkcampi('nome1,nome2,nome3,....')
'nome1,nome2,nome3 sono i nomi dei campi di input del form che si vuole
controllare
La funzione deve essere inserita nella apertura del form inserendo il campo
onsubmit = "return chkcampi('nome1,nome2,nome3,...')"
*/
{
var ncampo = NomeCampi.split(",");
var msg = "Attenzione !";
var chk = 1;
for (i=0;i < ncampo.length;i++)
{
var nome = ncampo[i];
if (document.forms[0].elements[nome].value=="")
{
msg=msg+"\n "+ document.forms[0].elements[nome].name.toUpperCase()+"
e\' un campo obbligatorio";
if (chk == 1)
{
var nome_focus = nome;
chk=0;
}
}
}
if (chk==0)
{
alert (msg);
document.forms[0].elements[nome_focus].focus();
}
}


La funzione viene chiamata dal form che allego


<?php
readfile ("header.html");
?>
Form con il metodo "onsubmit"
<form action="t2.html" onsubmit="return chkcampi('cognome,via')" name="modulo">
<table>
<tr>
<td>nome</td><td><input type="text" name="nome"></td>
<td>cognome</td><td><input type="text" name="cognome"></td>
<td>via</td><td><input type="text" name="via"></td>
</tr>
<tr>
<td><input type="submit"></td><td><input type="reset"></td>
</tr>

</table>


</form>

<?php
readfile ("footer.html");
?>


La funzione va in crisi sull'ultima istruzione di focus().
Dopo aver visualizzato il msg (nel caso debba essere visualizzato)
si vede che il focus passa per un attimo al campo corretto e poi subito
dopo viene portato al browser. Se premo il tasto TAB viene spostato il
focus sul primo campo del form.
Dove sbaglio ?

Grazie in anticipo per l'aiuto.

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.