PDA

View Full Version : Submit form by pressing enter



monkeyboy
01-26-2006, 07:40 PM
Hi there. I'm using the code below to execute a javascript function when a correct password is entered into a textbox. It works fine when the button is clicked, but not if users type in the password and then press 'enter'... is there some way I can get this to work?




<FORM ACTION="#" NAME=verify>
<input id="photos" type=password size=10>
&nbsp;&nbsp;
<input type="button" value="click" onclick="javascript:Check()">
</FORM>
<SCRIPT TYPE="TEXT/JAVASCRIPT">
document.verify.photos.focus()
</SCRIPT>



The page is here (http://www.chuffingmarvellous.com/photo/photos.htm).

Twey
01-26-2006, 07:52 PM
<form action="#" name="verify" onsubmit="Check();return false;">
<input id="photos" type="password" size="10">
&nbsp;&nbsp;
<input type="submit" value="click">
</form>
<script type="text/javascript">
document.forms['verify'].elements['photos'].focus();
</script>You shouldn't use document.name. Instead, document.getElementsByName(), document.getElementById(), and (in some cases) document.forms['name'] and document.images['name'] are available.
Also, you shouldn't include javascript: pseudo-protocol indicators in event handlers.

monkeyboy
01-26-2006, 07:59 PM
Works like a charm, thanks.