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 Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Single text field submit problem

Status
Not open for further replies.

Julian4145

Programmer
Oct 28, 2003
27
US
Hi All,
Been working on this a couple days now and can't seem to find a way around it. Apparently, when a form contains only a single text field and a submit button, hitting the enter key does not pass the submit button's name/value pairs. The only way the user can submit the form is too click the submit button with the mouse.

From what I have read, this seems to have been done by design in IE. (See
All I am looking for is to have a form with one text box and one submit button. When the user enters a value in the text box and presses the enter key, some minor javascript validation is done to ensure the text box is not empty and the value is a number and then completes a search. The javascript validation works fine and the search works fine when the submit button is clicked, but neither the javascript validation nor the search executes when the user hits enter.

Does anyone have a way around this?

Thanks in advance
Julian
 
How are you activating the javascript validation? If you are using the onClick event of the submit button then pressing Enter will not call it. You will need to use the onSubmit event of the Form.

Post your current code so we can see where you are.

Tony
________________________________________________________________________________
 
Here's my code. I added the onSubmit event to the EditTimestamp Form. So now when I hit enter the validation is executed and then the page submits, but I'm still not getting results. But if I click on the Find button, instead of hitting enter I do get results.

'txtID Validation
<script language="javascript">
function ValidateForm(){
if ((EditTimestamp.txtID.value == '') || (isNaN(EditTimestamp.txtID.value))){
alert('Please enter a valid ID.');
return false;
}
}
</script>

<%
If Request.Form("btnFind") <> "" then
ID = Trim(Request.Form("txtID"))
if ID <> "" then
'Execute SQL here to do search on ID
end if
elseif Request.Form("btnDone") <> "" then
'Exit Page
elseIf Request.Form("btnUpdate") <> "" then
ID = Request.Form("hidID")
NewTimeStamp = Request.Form("txtNewTimestamp")
if ID <> "" then
'Execute UPDATE SQL to update the timestamp on record here
UpdateMessage = "The timestamp for ID " & ID & " was updated to " & NewTimeStamp & "."
end if

'The message below is displayed because when a form has only one text field and the enter key is
'pressed to submit the form, the form submits without passing any values. This is what I am
'trying to get rid of.

else
UpdateMessage = "Please search again by clicking on the Find button with the mouse."
end if

%>

<HTML>
<HEAD>
<TITLE>Edit Timestamp</TITLE>
<link rel="stylesheet" href="/style/style.css" type="text/css">
</HEAD>

<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">

'My problem is in this form. It displays when the page is called. If I add a second text box in this form, and press 'enter the page submits fine. Otherwise it submits without passing any values.

<form name="EditTimestamp" method="post" action="EditTimestamp.asp" onSubmit="javascript:return ValidateForm();">
<table width="100%" cellspacing=2 cellpadding=2 border=0>
<tr bgcolor="#669999"><td><center><font size="+0" color="#ffffff"><b>Edit Timestamp Admin</center></font></td></tr>
</table>

<br>
<br>

<table width="100%" cellspacing=2 cellpadding=2 border=0>
<tr>
<td bgcolor="#669999"><b>ID:</b></td>
<td bgcolor="#ffffdd">
<input type="text" name="txtID">
<input type="submit" name="btnFind" value="Find">
<input type="submit" name="btnDone" value="Done">
</td>
</tr>
</table>
</form>

<br>
<br>

'This displays on the page after the search has been completed and results where returned.
<%If Request.Form("btnFind") <> "" then%>
<%If objRS("RecordID") <> "" then%>
<form name="UpdateTimestamp" action="edittimestamp.asp" method="post">
<table>
<tr>
<td bgcolor="#669999"><b>ID:</b></td>
<td bgcolor="#ffffdd"><%=ID%></td>
<input type="hidden" name="hidID" value="<%=ID%>">
</tr>
<tr>
<td bgcolor="#669999"><b>Current Timestamp:</b></td>
<td bgcolor="#ffffdd"><%=objRS("timestamp")%></td>
</tr>
<tr>
<td bgcolor="#669999"><b>New Timestamp:</b></td>
<td bgcolor="#ffffdd"><input size="25" type="text" name="txtNewTimestamp" value="<%=Now%>"></td>
<td><input type="submit" name="btnUpdate" value="Update Timestamp"></td>
</tr>
</table>
</form>
'Displays when no results exist
<%else%>
<p align="center"><font size="3"><b>No records exist matching ID <%=ID%>. Please search again.</b></font></p>
<%end if%>
<%end if%>

<%if UpdateMessage <> "" then%>
<p align="center"><font size="3"><b><%=UpdateMessage%></b></font>
<%end if%>
 
Its not the javascript. Whether the javascript is even there or not does not affect my problem. Maybe I didn't explain it clearly.

The problem I am having is when a user enters a value in the txtID field and presses the enter key (as opposed to clicking on the btnFind with the mouse) the page submits but does not pass any name/value pairs. If the user enters a value in txtID and then physically clicks the btnFind with the mouse, the page submits as expected and executes the search located in the code block:
If Request.Form("btnFind") <> "" then

It is the same problem outlined in this thread thread333-831351. But the solution in there was too get rid of the submit button and force a submitt on the text field. I am hoping there is another way.

Apparently in IE there is a quirk where if there is only a single text box in a form with a submit button, the submit button will not pass its name/value pairs when enter is hit. Clicking the submit button will do this however. Only when there are two or more text boxes in a form will hitting the enter key work. The link in my first post has more detail on this.

If I add a second text box to the edittimestamp form, and hit enter after entering a value in txtID, the If Request.Form("btnFind") code block does execute. I am wondering why this is (apparently it is by design in IE) and what I can do to get around it, have a single text box in a form with a submit button and have the ability for the user to hit enter to execute the If Request.Form("btnFind") code block.

Thanks
Julian
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top