Connecting Tech Pros Worldwide Forums | Help | Site Map

Enter key will not submit the form

M Smith
Guest
 
Posts: n/a
#1: Jul 22 '05
I have a form I want to submit to itself. I want to be able to type in a
list of numbers and submit the form and have that list show up on the same
form under the text box I typed them into and the buttons. The problem is
when I post a form to itself, the Enter key will not submit the form, it
only clears the contents of the text box. The only way I can submit is to
click the submit button. Here is a simplified version of my code that I had
to comment out so you could see the source. Note the name of the page is
Page1.asp

'<%@ Language=VBScript %>
'<HTML>
'<HEAD>
'</HEAD>
'<BODY>
'<p>Enter numbers separated by a comma.</p>
'<form action="Page1.asp" method="POST" id=form1 name=form1>
'<p><input type="text" name="ListID" size="50" maxlength="1000"></p>
'<p><input type="submit" value="Submit" name="B1"><input type="reset"
value="Reset" 'name="B2"></p>
'</form>
'<%if Request.Form("B1")="Submit" then
' lvListID=Request.Form("ListID")
' Response.Write lvListID
'End IF '%>
'</BODY>
'</HTML>

I know I've posted a page to itself before and had never had problems with
the Enter key not submitting. What am I doing wrong?
Thanks
Mike



Ray Costanzo [MVP]
Guest
 
Posts: n/a
#2: Jul 22 '05

re: Enter key will not submit the form


It most likely is submitting just fine. You're just not using the correct
criteria to determine if it was submitted. Try either evaluating your IF
statement based on the contents of Request.Form("ListID") or
Request.ServerVariables("REQUEST_METHOD"). To verify that your form is
submitting, try using this code and pressing enter:

<HTML>
<HEAD>
</HEAD>
<BODY>
<p>Enter numbers separated by a comma.</p>
<form action="page1.asp" method="POST" id=form1 name=form1>
<p><input type="text" name="ListID" size="50" maxlength="1000"></p>
<p><input type="submit" value="Submit" name="B1"><input type="reset"
value="Reset" name="B2"></p>
</form>
<%

For Each thing in Request.Form
Response.Write thing & " = " & Request.Form(thing) & "<hr />"
Next

%>
</BODY>
</HTML>

Ray at work

"M Smith" <msmith@avma.org> wrote in message
news:e91NCBG7EHA.2180@TK2MSFTNGP12.phx.gbl...[color=blue]
> I have a form I want to submit to itself. I want to be able to type in a
> list of numbers and submit the form and have that list show up on the same
> form under the text box I typed them into and the buttons. The problem is
> when I post a form to itself, the Enter key will not submit the form, it
> only clears the contents of the text box. The only way I can submit is to
> click the submit button. Here is a simplified version of my code that I[/color]
had[color=blue]
> to comment out so you could see the source. Note the name of the page is
> Page1.asp
>
> '<%@ Language=VBScript %>
> '<HTML>
> '<HEAD>
> '</HEAD>
> '<BODY>
> '<p>Enter numbers separated by a comma.</p>
> '<form action="Page1.asp" method="POST" id=form1 name=form1>
> '<p><input type="text" name="ListID" size="50" maxlength="1000"></p>
> '<p><input type="submit" value="Submit" name="B1"><input type="reset"
> value="Reset" 'name="B2"></p>
> '</form>
> '<%if Request.Form("B1")="Submit" then
> ' lvListID=Request.Form("ListID")
> ' Response.Write lvListID
> 'End IF '%>
> '</BODY>
> '</HTML>
>
> I know I've posted a page to itself before and had never had problems with
> the Enter key not submitting. What am I doing wrong?
> Thanks
> Mike
>
>[/color]


Bob Lehmann
Guest
 
Posts: n/a
#3: Jul 22 '05

re: Enter key will not submit the form


It's a bug in IE (imagine that). When there is only one text box, IE messes
it up.

I don't remember the work-around (funny that IE is now the browser to work
around), but I think if you add a hidden field, or a text box with the
visibilty hidden it will work.

Bob Lehmann

"M Smith" <msmith@avma.org> wrote in message
news:e91NCBG7EHA.2180@TK2MSFTNGP12.phx.gbl...[color=blue]
> I have a form I want to submit to itself. I want to be able to type in a
> list of numbers and submit the form and have that list show up on the same
> form under the text box I typed them into and the buttons. The problem is
> when I post a form to itself, the Enter key will not submit the form, it
> only clears the contents of the text box. The only way I can submit is to
> click the submit button. Here is a simplified version of my code that I[/color]
had[color=blue]
> to comment out so you could see the source. Note the name of the page is
> Page1.asp
>
> '<%@ Language=VBScript %>
> '<HTML>
> '<HEAD>
> '</HEAD>
> '<BODY>
> '<p>Enter numbers separated by a comma.</p>
> '<form action="Page1.asp" method="POST" id=form1 name=form1>
> '<p><input type="text" name="ListID" size="50" maxlength="1000"></p>
> '<p><input type="submit" value="Submit" name="B1"><input type="reset"
> value="Reset" 'name="B2"></p>
> '</form>
> '<%if Request.Form("B1")="Submit" then
> ' lvListID=Request.Form("ListID")
> ' Response.Write lvListID
> 'End IF '%>
> '</BODY>
> '</HTML>
>
> I know I've posted a page to itself before and had never had problems with
> the Enter key not submitting. What am I doing wrong?
> Thanks
> Mike
>
>[/color]


Ray Costanzo [MVP]
Guest
 
Posts: n/a
#4: Jul 22 '05

re: Enter key will not submit the form


Worked fine for me using IE.

Ray at work

"Bob Lehmann" <nospam@dontbotherme.zzz> wrote in message
news:%23P7dCFH7EHA.4028@TK2MSFTNGP15.phx.gbl...[color=blue]
> It's a bug in IE (imagine that). When there is only one text box, IE[/color]
messes[color=blue]
> it up.
>
> I don't remember the work-around (funny that IE is now the browser to work
> around), but I think if you add a hidden field, or a text box with the
> visibilty hidden it will work.
>
> Bob Lehmann[/color]


Dave Anderson
Guest
 
Posts: n/a
#5: Jul 22 '05

re: Enter key will not submit the form


M Smith wrote:[color=blue]
> ...The problem is when I post a form to itself, the Enter key
> will not submit the form, it only clears the contents of the
> text box...
>
> <input type="text" name="ListID" size="50" maxlength="1000">
> <input type="submit" value="Submit" name="B1">
> <input type="reset" value="Reset" 'name="B2">[/color]

It sounds as if the focus is on the RESET input. Does the behavior change if
you convert the RESET to a button?

<input type="button" value="Reset" onclick="this.form.reset()">



--
Dave Anderson

Unsolicited commercial email will be read at a cost of $500 per message. Use
of this email address implies consent to these terms. Please do not contact
me directly or ask me to contact you directly for assistance. If your
question is worth asking, it's worth posting.


Ray Costanzo [MVP]
Guest
 
Posts: n/a
#6: Jul 22 '05

re: Enter key will not submit the form


Dave, try it with the code he posted, and you'll see what I'm talking about.

Ray at work

"Dave Anderson" <GTSPXOESSGOQ@spammotel.com> wrote in message
news:uCovTxO7EHA.2600@TK2MSFTNGP09.phx.gbl...[color=blue]
> It sounds as if the focus is on the RESET input. Does the behavior change[/color]
if[color=blue]
> you convert the RESET to a button?
>
> <input type="button" value="Reset" onclick="this.form.reset()">
>[/color]


Dave Anderson
Guest
 
Posts: n/a
#7: Jul 22 '05

re: Enter key will not submit the form


Ray Costanzo [MVP] wrote:[color=blue]
> Dave, try it with the code he posted, and you'll see what I'm talking
> about.[/color]

Yeah, you're probably right, Ray.



--
Dave Anderson

Unsolicited commercial email will be read at a cost of $500 per message. Use
of this email address implies consent to these terms. Please do not contact
me directly or ask me to contact you directly for assistance. If your
question is worth asking, it's worth posting.


Ray Costanzo [MVP]
Guest
 
Posts: n/a
#8: Jul 22 '05

re: Enter key will not submit the form


Maybe the problem is actually that his sound his muted and he's not
hearing the Start Navigation sound. ;]

Ray at work

"Dave Anderson" <GTSPXOESSGOQ@spammotel.com> wrote in message
news:OqHR6$O7EHA.3836@tk2msftngp13.phx.gbl...[color=blue]
> Ray Costanzo [MVP] wrote:[color=green]
> > Dave, try it with the code he posted, and you'll see what I'm[/color][/color]
talking[color=blue][color=green]
> > about.[/color]
>
> Yeah, you're probably right, Ray.
>
>
>
> --
> Dave Anderson
>
> Unsolicited commercial email will be read at a cost of $500 per[/color]
message. Use[color=blue]
> of this email address implies consent to these terms. Please do not[/color]
contact[color=blue]
> me directly or ask me to contact you directly for assistance. If[/color]
your[color=blue]
> question is worth asking, it's worth posting.
>
>[/color]


Bob Lehmann
Guest
 
Posts: n/a
#9: Jul 22 '05

re: Enter key will not submit the form


You're right. I was close though.

The bug I was thinking about involved the submit button. When there is a
single textbox, and the "Enter" key is used to submit the form, the onclick
event of the submit button doesn't fire, nor is information about the button
sent to the server.

This discusses the problem in an ASP.Net context, but the same applies to
ASP pages.....
http://www.bbits.co.uk/blog/archive/2004/03/09/191.aspx

Bob Lehmann

"Ray Costanzo [MVP]" <my first name at lane 34 dot commercial> wrote in
message news:eS5QJPO7EHA.1596@tk2msftngp13.phx.gbl...[color=blue]
> Worked fine for me using IE.
>
> Ray at work
>
> "Bob Lehmann" <nospam@dontbotherme.zzz> wrote in message
> news:%23P7dCFH7EHA.4028@TK2MSFTNGP15.phx.gbl...[color=green]
> > It's a bug in IE (imagine that). When there is only one text box, IE[/color]
> messes[color=green]
> > it up.
> >
> > I don't remember the work-around (funny that IE is now the browser to[/color][/color]
work[color=blue][color=green]
> > around), but I think if you add a hidden field, or a text box with the
> > visibilty hidden it will work.
> >
> > Bob Lehmann[/color]
>
>[/color]


Ray Costanzo [MVP]
Guest
 
Posts: n/a
#10: Jul 22 '05

re: Enter key will not submit the form



"Bob Lehmann" <nospam@dontbotherme.zzz> wrote in message
news:%23Fksd%23P7EHA.3336@TK2MSFTNGP11.phx.gbl...[color=blue]
> You're right. I was close though.
>
> The bug I was thinking about involved the submit button. When there[/color]
is a[color=blue]
> single textbox, and the "Enter" key is used to submit the form, the[/color]
onclick[color=blue]
> event of the submit button doesn't fire, nor is information about[/color]
the button[color=blue]
> sent to the server.[/color]

Is that really a bug? I personally would only want an onclick event
to fire on click.

[color=blue]
> This discusses the problem in an ASP.Net context, but the same[/color]
applies to[color=blue]
> ASP pages.....
> http://www.bbits.co.uk/blog/archive/2004/03/09/191.aspx[/color]

In my opinion, it's a bug in ASP.NET and it's attempt to make a
client-server environment behave like it's not that.

Ray at work



Bob Lehmann
Guest
 
Posts: n/a
#11: Jul 22 '05

re: Enter key will not submit the form


>> Is that really a bug?
I'd be less inclined to think so if it wasn't for the fact that adding a
second textbox causes the onclick to fire on the client, and button
information (value) to be sent to the server when hitting "Enter".
[color=blue][color=green]
>> In my opinion, it's a bug in ASP.NET[/color][/color]
The same behavior in .asp and .htm pages.

Bob Lehmann

"Ray Costanzo [MVP]" <my first name at lane 34 dot commercial> wrote in
message news:uWM8qDQ7EHA.2516@TK2MSFTNGP09.phx.gbl...[color=blue]
>
> "Bob Lehmann" <nospam@dontbotherme.zzz> wrote in message
> news:%23Fksd%23P7EHA.3336@TK2MSFTNGP11.phx.gbl...[color=green]
> > You're right. I was close though.
> >
> > The bug I was thinking about involved the submit button. When there[/color]
> is a[color=green]
> > single textbox, and the "Enter" key is used to submit the form, the[/color]
> onclick[color=green]
> > event of the submit button doesn't fire, nor is information about[/color]
> the button[color=green]
> > sent to the server.[/color]
>
> Is that really a bug? I personally would only want an onclick event
> to fire on click.
>
>[color=green]
> > This discusses the problem in an ASP.Net context, but the same[/color]
> applies to[color=green]
> > ASP pages.....
> > http://www.bbits.co.uk/blog/archive/2004/03/09/191.aspx[/color]
>
> In my opinion, it's a bug in ASP.NET and it's attempt to make a
> client-server environment behave like it's not that.
>
> Ray at work
>
>
>[/color]


Roland Hall
Guest
 
Posts: n/a
#12: Jul 22 '05

re: Enter key will not submit the form


"M Smith" wrote in message news:e91NCBG7EHA.2180@TK2MSFTNGP12.phx.gbl...
:I have a form I want to submit to itself. I want to be able to type in a
: list of numbers and submit the form and have that list show up on the same
: form under the text box I typed them into and the buttons. The problem is
: when I post a form to itself, the Enter key will not submit the form, it
: only clears the contents of the text box. The only way I can submit is to
: click the submit button. Here is a simplified version of my code that I
had
: to comment out so you could see the source. Note the name of the page is
: Page1.asp
:
: '<%@ Language=VBScript %>
: '<HTML>
: '<HEAD>
: '</HEAD>
: '<BODY>
: '<p>Enter numbers separated by a comma.</p>
: '<form action="Page1.asp" method="POST" id=form1 name=form1>
: '<p><input type="text" name="ListID" size="50" maxlength="1000"></p>
: '<p><input type="submit" value="Submit" name="B1"><input type="reset"
: value="Reset" 'name="B2"></p>
: '</form>
: '<%if Request.Form("B1")="Submit" then
: ' lvListID=Request.Form("ListID")
: ' Response.Write lvListID
: 'End IF '%>
: '</BODY>
: '</HTML>
:
: I know I've posted a page to itself before and had never had problems with
: the Enter key not submitting. What am I doing wrong?
: Thanks
: Mike

The problem is the Submit button doesn't post a value when you press ENTER
from the text box. You're testing the value of the button and there isn't
one. If you tab to the button and press ENTER, SPACE or you click on the
submit button, then it posts the value of the button. It sounds like a bug
to me or (cough) a "by design" change.

I wouldn't test if a button had been pressed when submitting to a page if
I'm looking for a value from a text box. I would just check to see if the
value exists since it's posting to itself and it doesn't have a default
value, clearly it is there only if it had been posted. Yes, it could have
been posted from somewhere else but that is easy enough to test for also.

Adding a hidden field as Bob suggested doesn't make it work either. I
didn't check another text field with visibility: hidden or display: none.

You can restrict the ENTER key from being used to submit the form with:
<form action="Page1.asp" method="POST" id="form1" name="form1"
onsubmit="return false">

Then you can add onclick events to your buttons:
<p><input id="b1" type="button" value="Submit"
onclick="document.form1.submit()" />
<input id="b2" type="button" value="Reset"
onclick="document.form1.reset()" />
</p>

However, you're not going to get a value for the submit button. It appears
your approach is what needs to be modified because B1 will always =
"Submit", whether it gets submitted or not. What you need to test for is a
value in ListID and if found, display it. But, you can even eliminate that
test and just display it anyway since you have no presentable text with it.
If it's empty, it will not display and if it has content, it will.

Or, you can add a hidden field and set the value of the button, but I would
only do this if I had multiple buttons and I wanted to know which one was
pressed. If you only have the two, as you do currently, only the submit
button can submit the form. That's not the best way to validate a form
being posted upon entry.

I remember my first problem with forms was MAPI mail submissions including
the submit button. The way around it was to remove the name= from the
submit button so it did not include it. Perhaps MSFT over simplified it
now?! (O:=

Hidden field and ENTER key restricted from posting from the text field:
http://kiddanger.com/lab/msmith/page1.asp
Source:
http://kiddanger.com/lab/msmith/ss_page1.asp

Only change is displaying the value if it exists:
http://kiddanger.com/lab/msmith/page2.asp
Source:
http://kiddanger.com/lab/msmith/ss_page2.asp

HTH...

--
Roland Hall
/* This information is distributed in the hope that it will be useful, but
without any warranty; without even the implied warranty of merchantability
or fitness for a particular purpose. */
Technet Script Center - http://www.microsoft.com/technet/scriptcenter/
WSH 5.6 Documentation - http://msdn.microsoft.com/downloads/list/webdev.asp
MSDN Library - http://msdn.microsoft.com/library/default.asp


Dave Anderson
Guest
 
Posts: n/a
#13: Jul 22 '05

re: Enter key will not submit the form


Roland Hall wrote:[color=blue]
> The problem is the Submit button doesn't post a value when you press
> ENTER from the text box.[/color]

Unless (a) there are multiple TEXT inputs, or (b) the browser is not IE. It
is only the single text input case with Internet Explorer that exhibits this
behavior.


--
Dave Anderson

Unsolicited commercial email will be read at a cost of $500 per message. Use
of this email address implies consent to these terms. Please do not contact
me directly or ask me to contact you directly for assistance. If your
question is worth asking, it's worth posting.


Roland Hall
Guest
 
Posts: n/a
#14: Jul 22 '05

re: Enter key will not submit the form


"Dave Anderson" wrote in message
news:e8KAB$c7EHA.3076@TK2MSFTNGP15.phx.gbl...
: Roland Hall wrote:
: > The problem is the Submit button doesn't post a value when you press
: > ENTER from the text box.
:
: Unless (a) there are multiple TEXT inputs, or (b) the browser is not IE.
It
: is only the single text input case with Internet Explorer that exhibits
this
: behavior.

Yes, I agree it is an IE issue. Did it sound like I was saying something
different re: it being a bug?


Dave Anderson
Guest
 
Posts: n/a
#15: Jul 22 '05

re: Enter key will not submit the form


Roland Hall wrote:[color=blue][color=green]
>> Unless (a) there are multiple TEXT inputs, or (b) the browser is not
>> IE. It is only the single text input case with Internet Explorer
>> that exhibits this behavior.[/color]
>
> Yes, I agree it is an IE issue. Did it sound like I was saying
> something different re: it being a bug?[/color]

You certainly did not suggest it was an Internet Explorer bug. I personally
do not consider it a bug, since this is open to interpretation:

17.13.2 Successful controls
A successful control is "valid" for submission. Every successful
control has its control name paired with its current value as part
of the submitted form data set. A successful control must be
defined within a FORM element and must have a control name.

http://www.w3.org/TR/html401/interac...s.html#h-17.13

The above does not require that a submit button be considered successful --
it merely sets a threshold for such consideration. MS obviously does not
consider the button activated when [Enter] in pressed in the text input.

Who can say why? Perhaps this goes back to the transition from ISINDEX to
text inputs. Good question for the blogs, though.



--
Dave Anderson

Unsolicited commercial email will be read at a cost of $500 per message. Use
of this email address implies consent to these terms. Please do not contact
me directly or ask me to contact you directly for assistance. If your
question is worth asking, it's worth posting.


Bob Lehmann
Guest
 
Posts: n/a
#16: Jul 22 '05

re: Enter key will not submit the form


It's weird, though, that it is considered activiated when there is more than
one textbox in the form.

Bob Lehmann

"Dave Anderson" <GTSPXOESSGOQ@spammotel.com> wrote in message
news:%23dBgmTe7EHA.3592@TK2MSFTNGP09.phx.gbl...[color=blue]
> Roland Hall wrote:[color=green][color=darkred]
> >> Unless (a) there are multiple TEXT inputs, or (b) the browser is not
> >> IE. It is only the single text input case with Internet Explorer
> >> that exhibits this behavior.[/color]
> >
> > Yes, I agree it is an IE issue. Did it sound like I was saying
> > something different re: it being a bug?[/color]
>
> You certainly did not suggest it was an Internet Explorer bug. I[/color]
personally[color=blue]
> do not consider it a bug, since this is open to interpretation:
>
> 17.13.2 Successful controls
> A successful control is "valid" for submission. Every successful
> control has its control name paired with its current value as part
> of the submitted form data set. A successful control must be
> defined within a FORM element and must have a control name.
>
> http://www.w3.org/TR/html401/interac...s.html#h-17.13
>
> The above does not require that a submit button be considered[/color]
successful --[color=blue]
> it merely sets a threshold for such consideration. MS obviously does not
> consider the button activated when [Enter] in pressed in the text input.
>
> Who can say why? Perhaps this goes back to the transition from ISINDEX to
> text inputs. Good question for the blogs, though.
>
>
>
> --
> Dave Anderson
>
> Unsolicited commercial email will be read at a cost of $500 per message.[/color]
Use[color=blue]
> of this email address implies consent to these terms. Please do not[/color]
contact[color=blue]
> me directly or ask me to contact you directly for assistance. If your
> question is worth asking, it's worth posting.
>
>[/color]


Closed Thread