PC Review


Reply
Thread Tools Rate Thread

Disable Enter

 
 
=?Utf-8?B?U3RldmU=?=
Guest
Posts: n/a
 
      25th Jan 2006
How do I prevent users from submiting a form if they press the enter key. I
saw a script to disbale the enter key but I forget where. Any suggestions?
 
Reply With Quote
 
 
 
 
Trevor L.
Guest
Posts: n/a
 
      25th Jan 2006
Steve wrote:
> How do I prevent users from submiting a form if they press the enter
> key. I saw a script to disbale the enter key but I forget where. Any
> suggestions?


This works in a field
<input type="text" id="no" value="" size="1" maxlength="3"
onkeypress="return event.keyCode!=13"/>

--
Cheers,
Trevor L.
Website: http://tandcl.homemail.com.au


 
Reply With Quote
 
=?Utf-8?B?QU15c3RpY1dlYg==?=
Guest
Posts: n/a
 
      25th Jan 2006
Hi Steve,

http://frontpageforms.com/disable_enter.htm


Mike Smith,

http://FrontPageForms.com
FrontPage Form Tutorials
& Form Script Examples



"Trevor L." wrote:

> Steve wrote:
> > How do I prevent users from submiting a form if they press the enter
> > key. I saw a script to disbale the enter key but I forget where. Any
> > suggestions?

>
> This works in a field
> <input type="text" id="no" value="" size="1" maxlength="3"
> onkeypress="return event.keyCode!=13"/>
>
> --
> Cheers,
> Trevor L.
> Website: http://tandcl.homemail.com.au
>
>
>

 
Reply With Quote
 
Trevor L.
Guest
Posts: n/a
 
      25th Jan 2006
AMysticWeb wrote:
> Hi Steve,
>
> http://frontpageforms.com/disable_enter.htm
>
>
> Mike Smith,
>
> http://FrontPageForms.com
> FrontPage Form Tutorials
> & Form Script Examples


Mike,
I made the first suggestion and you followed it up with a mroe general
function
function checkCR(evt) {
var evt = (evt) ? evt : ((event) ? event : null);
var node = (evt.target) ? evt.target : ((evt.srcElement) ?
evt.srcElement : null);
if ((evt.keyCode == 13) && (node.type=="text")) {return false;}
}
document.onkeypress = checkCR;

Here is something which has interested me for some time
Please explain my ignorance

Point 1. An event is set equal to a function
I take this to mean:
When the event document.onkeypress occurs, execute the function
checkCR(evt)

Point 2. A function checkCR is defined with a parameter evt that is never
passed to it
I don't undertand this.
How can the function check for the existence of evt as a passed parameter
when it is never passed ?
The first line seems to mean:
If the parameter evt exists set local variable evt equal to the value of the
parameter evt
Else
If the global variable event exists set local variable evt equal to the
value of the global variable event
Else
Set local variable evt equal to null

The second line seems to mean:
If evt.target exists set local variable node equal to evt.target
Else
If evt.srcElement exists set local variable node equal to evt.srcElement
Else
Set local variable node equal to null

I assume therefore that these are known (or may be known depending on the
browser)
evt OR event
evt.target OR event.target OR evt.srcElement OR event.srcElement
evt.keyCode OR event.keyCode
evt.target.node.type OR event.target.node.type OR
evt.targetsrcElement.node.type OR event.target.srcElement.node.type

Can you state what these entities are
I assume:
evt or event is:
some event such as keypress. What are the other possibilities?
evt.target OR event.target OR evt.srcElement OR event.srcElement is:
the element where the event takes place, e.g. an <input> tag which has a
kepypress event
evt.keyCode OR event.keyCode is:
the keyCode associated with the event (e.g. a keypress)
evt.target.node.type OR event.target.node.type OR
evt.targetsrcElement.node.type OR event.target.srcElement.node.type is:
the type of the element where the event takes place, e.g. "text" or
"textarea"

However, I note that the code does not contain any element with type="text"
Is node.type="text" a generic type which includes <input> and <textarea> ?
Any others?

--
Cheers,
Trevor L.
Website: http://tandcl.homemail.com.au


 
Reply With Quote
 
Andrew Murray
Guest
Posts: n/a
 
      25th Jan 2006
A good way of preventing the form being submitted before the last field if
they press Enter in error, is to make the last field "required", so it won't
submit until they fill in the last field.

I believe there are also scripts around that make the Enter key behave like
the [Tab] key, that is it advances to the next field, then the user clicks
"Submit" rather than pressing the Enter key. Else make it plain they have
to press TAB to go to the next field, not [Enter].

"Steve" <(E-Mail Removed)> wrote in message
news:654B3CC4-40FA-4D59-8705-(E-Mail Removed)...
> How do I prevent users from submiting a form if they press the enter key.
> I
> saw a script to disable the enter key but I forget where. Any suggestions?



 
Reply With Quote
 
Trevor L.
Guest
Posts: n/a
 
      25th Jan 2006
Andrew Murray wrote:
> A good way of preventing the form being submitted before the last
> field if they press Enter in error, is to make the last field
> "required", so it won't submit until they fill in the last field.
>
> I believe there are also scripts around that make the Enter key
> behave like the [Tab] key, that is it advances to the next field,
> then the user clicks "Submit" rather than pressing the Enter key. Else
> make it plain they have to press TAB to go to the next field,
> not [Enter].


That sounds interesting. I am sure I have seen this behaviour on many
commercial sites.

Does anyone out there know of such a script?
I suppose it would be like the one on
http://frontpageforms.com/disable_enter.htm
but with a small change
e.g.
function checkCR(evt)
{
var evt = (evt) ? evt : ((event) ? event : null)
var node = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement
: null)
if ((evt.keyCode == 13) && (node.type=="text"))
{ evt.keyCode = xx
// where xx is the keycode for Tab
return true } // is this correct?
}
document.onkeypress = checkCR

Any ideas, people out there

--
Cheers,
Trevor L.
Website: http://tandcl.homemail.com.au


 
Reply With Quote
 
Trevor L.
Guest
Posts: n/a
 
      25th Jan 2006
Trevor L. wrote:

> Does anyone out there know of such a script?
> I suppose it would be like the one on
> http://frontpageforms.com/disable_enter.htm
> but with a small change
> e.g.
> function checkCR(evt)
> {
> var evt = (evt) ? evt : ((event) ? event : null)
> var node = (evt.target) ? evt.target : ((evt.srcElement) ?
> evt.srcElement
>> null)

> if ((evt.keyCode == 13) && (node.type=="text"))
> { evt.keyCode = xx
> // where xx is the keycode for Tab
> return true } // is this correct?
> }
> document.onkeypress = checkCR
>
> Any ideas, people out there


In an attempt to try out my ideas. I used this code
<input type="text" id="no" value="" size="1" maxlength="3"
onkeypress="event.keyCode = (event.keyCode ==13)? 9
:event.keyCode"/>

The idea was to change 13 (Enter) to 9 (Tab) but it didn't work
--
Cheers,
Trevor L.
Website: http://tandcl.homemail.com.au


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

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
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Disable Enter Key Julie Microsoft Access Forms 1 19th Dec 2007 08:03 AM
How to disable imagebutton postback when i enter "enter" =?Utf-8?B?am9l?= Microsoft ASP .NET 0 28th Sep 2006 07:46 AM
disable enter key Stephen Microsoft ASP .NET 3 28th Jul 2004 06:18 PM
disable enter key Stephen Microsoft Dot NET Framework 0 26th Jul 2004 07:58 PM
Disable Enter and Tab key Tom Microsoft Access Form Coding 6 20th Jun 2004 10:22 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:56 AM.