Tutorials & Script Homepage
HTML/DHTML 22to28
Basic Hyperlinks
Forms (Part 1)
Forms (Part 2)
Forms (Part 3)
Forms (Part 4)
Forms (Part 5)
Forms (Part 6)
advertisment
advertisement
advertisement
Host With Us: HostingHelper.co.uk From Only $5.00p/m
Spotted an Error ? Let us Know
100's more FREE templates at FreeWebTemplates
Looking for a new Web Host ?
Free templates from TemplatesLand
Professional High-End Templates
TemplateBox.com more FREE templates
Free Flash Templates and Intros
advertisement
 
HTML/DHTML TUTORIAL NUMBER : 26
Please Click Here, and Help Keep This Site FREE to Use
 
Please click on our sponsors advert to the right if you download or use anything from this page.
Thank you for your help.
This tutorial has been created by: HtmlCodeTutorial.com

Forms (Part 4)

Submit The Form When The User Presses Enter
Different browsers have different default behaviors about what to do when the user hits enter in a form. MSIE almost always submits the form, while Netscape will often just beep at you. Although it's usually best to leave the default browser behavior as it is, for some forms people just naturally tend to hit "enter" when they are ready. This is particularly true for login forms. With a little JavaScript we can set the form to submit on enter.

First, copy this script exactly as-is into the <HEAD> section of your document:

<SCRIPT TYPE="text/javascript">
<!--
function submitenter(myfield,e)
{
var keycode;
if (window.event) keycode = window.event.keyCode;
else if (e) keycode = e.which;
else return true;

if (keycode == 13)
   {
   myfield.form.submit();
   return false;
   }
else
   return true;
}
//-->
</SCRIPT>

For each field which should submit the form when they hit enter add an onKeyPress attribute like this:

<FORM ACTION="../cgi-bin/mycgi.pl">
name:     <INPUT NAME=realname SIZE=15><BR>
password: <INPUT NAME=password TYPE=PASSWORD SIZE=10
           onKeyPress="return submitenter(this,event)"><BR>
<INPUT TYPE=SUBMIT VALUE="Log In">
</FORM>

Add the attribute like it is in the example. No modification is needed. This gives us this form:


name:
password:


I hope this came in useful!
Ask in the forum if you have any suggestions or comments.

Web Hosting  |  Membership website templates  |  Reliable UK Web Hosting  |  Dallas Web Design  |  Art Web Templates  |  Cheap Flight Deals  |  Free Web Hosting  |  UK Web Hosting Company  |  Coursework Writing  |  Reseller Hosting  |  Directory Submission Service  |  Cheap UK Web Hosting  |   Youth hostels  |  Web Design  |  Low Cost Domain Names  |  Windows Hosting ASP.NET  |  Website templates  |  Broadband Reseller  |  Dedicated Server  |  Business Broadband  |  Professionelt webdesign firma - webbureau  |  Austin Web Design  |  Flash Templates  |   SEO Services India  |  Flash Intros  |  Web Templates  |  Cheap Web Hosting  |  Hyper-V Hosting  |  Website Templates  |  Corporate Logo Design Service  |  SEO  |  UK Dedicated Server Hosting  |  Best Web hosting  |  Bespoke Software Development  |  Domain Name Registration  |   Free Web Hosting  |  UK Web Hosting  |  Dating Software - aeDating 4.1  |  Flash Templates  |  Website Templates  |  Power Saver  |  Website Design Quote  |  Flash templates  |  cctv cameras  |  SEO  |  Web Templates  |  Web Design uk  |   Flash templates  |  Cheap Web Hosting Deal  |  Linux Hosting  |  Web Design uk  |  Web Hosting  |  Business web directory  |  Accept Credit Cards  |  Mobile Phone Contracts  |  Car Rental Deals  |  Free domain names  |  Business Email  |  Best UK web Hosting  |  

 
advertisment
advertisment
advertisment
advertisment
  Top-end templates
  Credit Cards
  Reseller web hosting UK
  free flash tutorials
  Web Hosting
  Hosting Directory
  Corporate Gifts
  Company Logos
  Christian Designs
  Website Templates
  Website Templates
  Web Hosting UK
  Free Web Templates
  Custom site design
  Domain Names
  Logo Design Pro UK
  Free Flash
  templatebox.com
  freewebtemplates.com
  templatesland.com
  topfreegraphics.com
  freegraphicland.com
  free-templates-layouts
  Ink & Toner Cartridges
  Layouts4Free
  Webmaster Resoucres
  Web Templates Factory
  Free Web Templates
  Free Templates Catalog
  Web Templates
  Reseller Web Hosting
  Stock Photography
  Animations-galore.com
  4print.com.au
  Host Review
  Web Hosting Host Color
  Dedicated Servers
  FlashTemplateDesign
  ZeroDollarTemplates
  Killersites.com
  how-to-build-websites
  Build a free website
  web Hosting
  Business Logo Design
  Templates Favpage
  webmastermind.de
  flasheasy.com
  More Featured Sites