Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Disable return button

Status
Not open for further replies.

nmath

Programmer
Dec 12, 2003
47
US
Does anyone know of a way to disable the return button on a page? I have form that has an onblur check on a field and if enter is pressed multiple times the form will submit with inproper data. I would like to disable the return button and require mouse clicks only. Thanks in advance for your help!
 
have you thought about validating the form ?

<HTML>
<HEAD>
</HEAD>
<BODY>
<SCRIPT LANGUAGE=&quot;JavaScript&quot;>
<!--
function valid(form) {
var field = form.age;
var userAge = parseInt(field.value);
if (!userAge) {
alert(&quot;You must indicate your age.&quot;);
return false;
} else if (userAge >= 18) {
alert(&quot;Thank your for your resume.&quot;);
return true;
} else {
alert(&quot;You are only &quot; + userAge + &quot;. Try again when you are 18.&quot;);
field.focus();
field.select();
return false;
}
}
// -->
</SCRIPT>

<FORM METHOD=&quot;POST&quot;
ACTION=&quot;mailto:you@yourdomain.com&quot;
ENCTYPE=&quot;text/plain&quot;
onSubmit=&quot;return valid(this)&quot;>
Your age:<BR><INPUT TYPE=&quot;text&quot; NAME=&quot;age&quot; SIZE=&quot;2&quot;><BR>
Desired Job:<BR><INPUT TYPE=&quot;text&quot; NAME=&quot;job&quot; SIZE=&quot;40&quot;><BR>
Resume:<BR><TEXTAREA NAME=&quot;resume&quot; COLS=&quot;40&quot; ROWS=&quot;5&quot;></TEXTAREA><BR>
<INPUT TYPE=&quot;submit&quot; VALUE=&quot;Send Resume&quot;>
</FORM>
</BODY>
</HTML>
 
Thanks for the suggestion!! I do have a validate form function. I have two buttons, one validates the form and makes sure that the type is correct and certain fields are entered and saves without the ability to come back and edit. The other button simply saves (I am working with ASP and SQL database) with the option to come back and edit. The fields do not have to filled in if the user clicks save w/ the option to edit later so I kinda wanted to eliminate the checking of the entire form because the data entered really doesn't matter. I just want to eliminate (if possible) the submission of the form simply by hitting enter repeatedly since that may not be the desired result when closing an alert window.
 
nmath,

This was a piece of code I used a while back and it did the trick at the time. When a user (in the password field) hits the enter key, the form is automatically submitted. Checks are obviously done to ensure that the username and the password fields are not empty before submitting.

Hope this helps:

Code:
<form name=&quot;Login&quot;... >
    Username: <input type=&quot;text&quot; name=&quot;username&quot;><br>
    Password: <input type=&quot;password&quot; name=&quot;password&quot;>
</form>

...

<script language=&quot;Javascript&quot;>
<!--
function lemmein(keypressed) {
    var agt = navigator.userAgent.toLowerCase();
    var is_ie = ((agt.indexOf(&quot;msie&quot;) != -1) && (agt.indexOf(&quot;opera&quot;) == -1));
    var is_gecko = (agt.indexOf(’gecko’) != -1);
    var key;
    if (is_ie) {
        key=window.event.keyCode;
    } else if (is_gecko) {
        key=keypressed.keyCode;
    } else {
        key=keypressed.which;
    }
    // Check if the ENTER key was hit
    if (key == 13) {
        if (loginValidation() != false) {
            document.Login.submit();
        }
    }
}
if (document.Login && document.Login.username) {
    document.Login.username.focus();
    document.Login.password.onkeypress=lemmein;
}
//-->
</script>

Pete.


Web Developer / Aptrix CMS (LWWCM) Specialist
w: e: Pete.Raleigh(at)lclimited.co.uk
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top