FatCow is one of the leading webhost in the internet today. FatCow Web Hosting. Free Trial , Free Setup, Free Support, All risk free!
Visit: FatCow.com
Post subject: Prevent form submission from return/enter key
Posted: Mon Feb 08, 2010 6:42 pm
Joined: Mon Feb 08, 2010 6:21 pm Posts: 1
Sorry, i post this topic here; i'm using my own php contact form script at this moment. My question is how can i prevent Form Submission when User Presses the Enter / Return key on a text field?
Post subject: Re: Prevent form submission from return/enter key
Posted: Tue Feb 09, 2010 3:24 pm
Site Admin
Joined: Wed Nov 05, 2008 8:04 am Posts: 90
To disable enter key on form submission you have to use JavaScript. Add the following JavaScript code between <head> and </head> tag at the top of your contact form.
Code:
<script type="text/javascript"> <!-- var flag=false; function setFlag(){flag=true;} function getFlag(){return flag;} --> </script>
In your form tag add the following onsubmit event handler. <form action= ...... onsubmit="return getFlag()"> In the submit button input add the following onclick event handler. <input type="submit" value= ...... onclick="setFlag()" /> Now user can submit form only by clicking the submit button. Enter or Return key will not work.
Users browsing this forum: No registered users and 1 guest
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot post attachments in this forum