-
Enter Key Disabling/Form Validation
Does anyone have a script which I can use to prevent the sending of
form information when the user hits the enter key?. I have seen
several scripts that purport to solve this problem, but none of them
work. I have tried to code my own script, but so far no luck, mainly
the enter key ascii equivalent, but so far no luck. Appreciate any help.
Mike Ewert
-
Re: Enter Key Disabling/Form Validation
Hi Mike --
"Mike Ewert" <ewert@flashmail.com> wrote in message
news:3b26a516@news.devx.com...
>
> Does anyone have a script which I can use to prevent the sending of
> form information when the user hits the enter key?. I have seen
> several scripts that purport to solve this problem, but none of them
> work. I have tried to code my own script, but so far no luck, mainly
> the enter key ascii equivalent, but so far no luck. Appreciate any help.
>
>
> Mike Ewert
>
Just off the top of my head, don't make your button a submit button, but
just a regular button. Then onClick(), call your submit routine.
<form name=form1>
<input type="button" value="Submit" name="cmdSubmit"
onClick="SubmitForm();">
</form>
<script language="javascript">
function SubmitForm()
{
document.form1.submit();
}
</script>
By making the button type="button", pressing enter won't cause the button to
submit the form.
-Matt
-
Re: Enter Key Disabling/Form Validation
Change the action attribute of the form so that it calls a script function.
You can then submit the form to the appropriate location within the function
after processing the form data, or you can prevent submission altogether.
"Mike Ewert" <ewert@flashmail.com> wrote in message
news:3b26a516@news.devx.com...
>
> Does anyone have a script which I can use to prevent the sending of
> form information when the user hits the enter key?. I have seen
> several scripts that purport to solve this problem, but none of them
> work. I have tried to code my own script, but so far no luck, mainly
> the enter key ascii equivalent, but so far no luck. Appreciate any help.
>
>
> Mike Ewert
>
-
Re: Enter Key Disabling/Form Validation
Oops!
"Matt Markus" <matt_markus@hotmail.com> wrote in message
news:3b30be10@news.devx.com...
> Hi Mike --
>
> "Mike Ewert" <ewert@flashmail.com> wrote in message
> news:3b26a516@news.devx.com...
> >
> > Does anyone have a script which I can use to prevent the sending of
> > form information when the user hits the enter key?. I have seen
> > several scripts that purport to solve this problem, but none of them
> > work. I have tried to code my own script, but so far no luck, mainly
> > the enter key ascii equivalent, but so far no luck. Appreciate any help.
> >
> >
> > Mike Ewert
> >
>
> Just off the top of my head, don't make your button a submit button, but
> just a regular button. Then onClick(), call your submit routine.
>
> <form name=form1>
> <input type="button" value="Submit" name="cmdSubmit"
> onClick="SubmitForm();">
> </form>
>
> <script language="javascript">
> function SubmitForm()
> {
> document.form1.submit();
> }
> </script>
>
> By making the button type="button", pressing enter won't cause the button
to
> submit the form.
>
>
> -Matt
>
>
Ok, I just found some problems with my previous example, so try this
instead:
<form name=form1 action=post.htm method=post>
<input type=button name=cmdSubmit value="click" onfocus="RedirectFocus();"
onClick="SubmitForm();">
<input type=text name=text1 size=20>
<input type=text name=text2 size=20>
</form>
<script language="javascript">
function SubmitForm()
{
document.form1.submit();
}
function RedirectFocus()
{
document.form1.text2.focus();
}
</script>
Cheesey, but it works.
It seems that when the text box next to the button receives the focus, so
does the button, and thus pressing enter will then cause that button to be
clicked. So just set the focus to another control every time that button
receives the focus.
Hope this helps!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks