PDA

View Full Version : turning "enter" keystroke into a 'click' on the submit button



canadianjameson
Nov 21st, 2006, 10:23 PM
Hey,

quick problem with a form a friend is using. If the user hits ENTER, the form submits but fails. When the user actually clicks the submit button, it works.

I remembered that I had a keycatcher script that I had modified once before to catch the 'enter' keystroke and turn in into a 'tab'

<script language="javascript" type="text/javascript">
function checkCR(evt) {
var evt = (evt) ? evt : ((event) ? event : null);
if (!evt) return true;
var node = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null);
if (evt.keyCode == 13 && node && node.type=="text") {
evt.keyCode = 9; //tab
return true;
}
}
document.onkeydown = checkCR;

</script>

I was wondering what I would have to change this to

evt.keyCode = 9; //tab
return true;
to have it submit the form. something like (but obviously not)
document.formname.submitButtonName.click = true;
return false //(?)

Mongus
Nov 22nd, 2006, 04:36 AM
It soulds like the form handler on the server is requiring the name of the button to be passed in as one of the parameters when the form is posted. What I'd do is either modify the URL of the form handler or append a hidden field to the form with the same name as the button. Neither of those require the user to have JavaScript enabled.

canadianjameson
Nov 23rd, 2006, 11:30 PM
Hey,

I understand your logic but i dont know how to do it... here's the page code, its very short. could you show me what you meant?



<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="GENERATOR" content="Mozilla/4.61 [en] (Win95; U) [Netscape]">
<title>Session Registration</title>
<style TYPE="text/css"><!-- A:link, A:visited, A:active { text-decoration: none } .white { color: #ffffff;
--></style>
</head>
<body bgcolor="#FFFFFF" link="#006600" vlink="#880000" alink="#000000">

<form method="post" action="FMPro""><input type="hidden" name="-db" value="mrp reg.fp5"><input type="hidden" name="-format" value="courseinfoMain.htm">
<input type="hidden" name="-lay" value="Form View">
<input TYPE="hidden" NAME="-error" VALUE="errorreg.htm">

&nbsp;
<center>
<table border=0 cellspacing=0 cellpadding=5 width="80%">
<tr>
<td>
<center>
<table width="100%" border="0" cellspacing="2" cellpadding="0">
<tr>
<td><img src="JMHorACo1.jpg" alt="" height="42" width="250" border="0"></td>
<td>
<div align="center">
<b><font size="3" color="#336633" face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular">Marketing Research Practicum</font></b></div>
</td>
</tr>
</table>
</center>
</td>
</tr>


<tr>
<td VALIGN=TOP BACKGROUND="logo.jpg">
<center>
<br>
<font size="4" color="#336633" face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular"><b>Study Session Information<br>
<br>
</b></font></center>

<table BORDER=0 WIDTH="100%" >
<tr>
<td>
<center>
<p><b><font size="3" face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular">Please enter your Student ID #:</font><br>
<br>
</b>
</center>
<input type="hidden" name="-op" value="equals">
<center>
<input type="password" name="student id"><br>
<font size="+1"><input type="submit" name="-find" value="click here to view or cancel your study sessions">
</font>
<p><b><font color="red" face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular">Note: Do not press the enter key or you will get an error message, you must click the button above.</font></b></p>
</center>
</td>
</tr>
</table>
</td>
</tr>
</table>
</center>

</body>
</html>

Mongus
Nov 24th, 2006, 04:09 PM
Try this:
<form method="post" action="FMPro"><input type="hidden" name="-find" value="1"/>

BTW, you had an extra quotation mark in the form tag after FMPro.

canadianjameson
Dec 3rd, 2006, 07:19 PM
sorry for the MASSIVE delay, i lost the post.

did you want me to change it from this:

<form method="post" action="FMPro">
<input type="hidden" name="-db" value="mrp reg.fp5">
<input type="hidden" name="-format" value="courseinfoMain.htm">
<input type="hidden" name="-lay" value="Form View">
<input TYPE="hidden" NAME="-error" VALUE="errorreg.htm">
to this:

<form method="post" action="FMPro">
<input type="hidden" name="-find" value="1"/>

or add it in like so:

<form method="post" action="FMPro">
<input type="hidden" name="-find" value="1"/>
<input type="hidden" name="-db" value="mrp reg.fp5">
<input type="hidden" name="-format" value="courseinfoMain.htm">
<input type="hidden" name="-lay" value="Form View">
<input TYPE="hidden" NAME="-error" VALUE="errorreg.htm">


again I appologize, i dont have access to the server on which this is being held so i cannot test it :( (and dont want to tell them to make a change that will kill the form entirely)

brandonH
Dec 4th, 2006, 02:06 AM
instead of trying to locate the submit button and .click(), give the form a name and do as follows:



document.formname.submit()

_Aerospace_Eng_
Dec 4th, 2006, 02:20 AM
I noticed you don't even have a closing form tag. Where is it?

canadianjameson
Dec 4th, 2006, 04:57 AM
Hey all,

You'll have to excuse me the uglyness / incompleteness of the code; it isnt mine. It is for my university's marketing research practicum signup page wherein they have a notice informing people NOT to press 'enter' to submit the form or it will fail.

I thought, as brandon just suggested, that there is a simple way around this... and so being me I offered to help fix the page.

so basically the question is how do i take the code and eliminate the error that is causing this form to fail if ENTER is pressed, but not if the submit button is clicked.

I hate to ask this, but as I have absolutely no means to test this... can one of you with more coding experience 'fix' the problem and past me the form code. I basically have to say "replace THIS with THIS" and if the code fails the whole system goes down :(

_Aerospace_Eng_
Dec 4th, 2006, 06:30 AM
Sighs. Why would you volunteer to do something that you didn't know how to do? We've told you the possible solutions. Up to you to some how test them. We can't do that for you as we don't have the server side script being used to submit the form sorry.

brandonH
Dec 4th, 2006, 07:08 AM
create a backup copy of the original source code. then test away. if all else fail, put the original source code back. and all should be good (no system down).

Mongus
Dec 4th, 2006, 03:23 PM
My response was to add the field, not replace all the other fields. If you add it the server will receive the same parameters when you press enter and when the button is clicked. When the button is clicked it will get two copies of the find parameter but it shouldn't affect the script that's handling the post. Doing it this way does not rely on JavaScript.