Go Back   Dynamic Drive Forums > General Coding > JavaScript
Search Dynamic Drive Forums:

Reply
 
Thread Tools Search this Thread
  #1  
Old 01-26-2006, 07:40 PM
monkeyboy monkeyboy is offline
Junior Coders
 
Join Date: Jan 2006
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default Submit form by pressing enter

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?

Code:
            <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.
Reply With Quote
  #2  
Old 01-26-2006, 07:52 PM
Twey's Avatar
Twey Twey is offline
Modtoreador
 
Join Date: Jun 2005
Location: 英国
Posts: 11,933
Thanks: 1
Thanked 180 Times in 172 Posts
Blog Entries: 2
Default

Code:
<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.
__________________
Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

Last edited by Twey; 01-26-2006 at 07:59 PM.
Reply With Quote
  #3  
Old 01-26-2006, 07:59 PM
monkeyboy monkeyboy is offline
Junior Coders
 
Join Date: Jan 2006
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Works like a charm, thanks.
Reply With Quote
Reply

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

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

Forum Jump


All times are GMT. The time now is 08:21 PM.

Home - Contact Us - Archives - Link to DD - Top 

Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.