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






Avrei bisogno di un aiuto per un problema con il focus sui campi.

Dal codice html che riporto richiamo la funzione chkcampi() che deve
controllare se il campo è vuoto o meno

**************** CODICE HTML

<?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");
?>



******************* CODICE JAVASCRIPT

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"; /* questa riga è a
capo solo per
l'invio nel ng */
if (chk == 1)
{
var nome_focus = nome;
chk=0;
}
}
}
if (chk==0)
{
alert (msg);
/* setTimeout('document.forms[0].elements[nome_focus].focus();',200); */
document.forms[0].elements[nome_focus].focus();
}
return
}


Il problema è che quando si chiude l'ultimo alert(msg) il focus mi passa per
un attimo sul campo giusto e poi si sposta subito alla finestra del
browser.
Il tutto gira sotto Linux RedHat 9.0, Apache 2.0.40, Mozilla 1.2.1.
Dove sbaglio ?

Grazie in anticipo per l'attenzione.

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.