"M Smith" wrote in message news:e9**************@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