Originariamente inviato da willybit
non importa sono opzionali...
lo script sopra funzia bene se nel form non č presente il tasto submit... se c'č il tasto submit quando si preme invio si fa il submit del form
io avrei fatto solo cosė
codice:
function check(evt){
if(evt.keyCode==13)evt.keyCode=9;
}
ma ho scoperto che con FF keyCode č di sola lettura
ci avevo provato anch'io
cmq, basta aggiungere i return per i bottoni. Cosė dovrebbe saltare i bottoni submit.
codice:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Documento senza titolo</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<script type="text/javascript">
function check(obj, evt)
{
var charCode = (evt.charCode)?evt.charCode : ((evt.which)?evt.which:evt.keyCode)
var key = charCode
if (key==13) {
do
if (obj!=null && obj.nextSibling!=null) obj=obj.nextSibling
else obj=obj.parentNode.firstChild
while (obj.nodeType!=1 || obj.type=='submit')
obj.focus()
return false
}
return true
}
</script>
</head>
<body>
<form name="form1" method="post" action="asd.php">
<input name="field1" type="text" id="field1" onKeyPress="return check(this, event)" />
<input name="field2" type="text" id="field2" onKeyPress="return check(this, event)" />
<input name="field3" type="text" id="field3" onKeyPress="return check(this, event)" />
<input type="submit" name="Submit" value="Invia" onKeyPress="return check(this, event)">
</form>
</body>
</html>