View Full Version : Form action/onsubmit ?
alpine
01-21-2003, 05:41 PM
I have a form that allows the user to enter some text in an input box and then submit the info to a javascript function.
I would like the function called when the user hits an enter button after typing in the data. As it is, the only way I can seem to call the function is by using a submit button -
<FORM name=frmSearch onSubmit="legalpre()">
<INPUT TYPE=hidden NAME=QUERYTYPE Value=BUILDLEGAL>
<INPUT TYPE=hidden NAME=QUERY Value=SELECT>
<INPUT TYPE=input NAME=QVALUE size="7">
<INPUT TYPE=SUBMIT VALUE="Search" onClick="legalpre()">
</FORM>
Thanks
PauletteB
01-21-2003, 10:46 PM
Maybe
<form name="frmSearch" action="javascript:legalpre()" method="post">
<input type="hidden" name="QUERYTYPE" value="BUILDLEGAL">
<input type="hidden" name="QUERY" value="SELECT">
Search <input type="text" name="QVALUE" size="7">
</form>
brothercake
01-21-2003, 11:05 PM
if your form has a SUBMIT button, then by default, the enter key will submit the form ..
unless you're preventing it; i think you need to pass proper return values, so
onsubmit=" return legalpre()"
then in the function you have to "return true"
alpine
01-22-2003, 05:04 PM
Grrrrrr......
Thanks for your responses. It's given me some ideas. Still no luck though.
The following code works.... to a degree.
The alert fires but temp.htm does not write.
<SCRIPT LANGUAGE=javascript>
function legalpre()
{
alert(document.frmSearch.QVALUE.value);
parent.TextFrame.location="temp.htm";
}
</SCRIPT>
</head>
<BODY>
<FORM name=frmSearch onSubmit="javascript:legalpre();">
<input name=QVALUE size=7>
<INPUT TYPE="submit" VALUE="Search">
</FORM>
</CENTER>
</BODY>
</HTML>
If I change INPUT TYPE="button" onClick="javascript:legalpre();"
The alert fires, temp.htm writes but pressing enter will not fire anything.
Thanks
Doug.
alpine
01-22-2003, 08:21 PM
AHA!
The problem is that I am trying to update the same frame that the code exists in.
For some reason type=button will do it.
Type=Submit won't
Anyone know any work arounds?
Thanks
MrDoubtFire
01-22-2003, 08:36 PM
So, the problem is that having a normal "button" button, won't write temp.htm, but everything else you want will work?
Also, shouldn't it be:
parent.TextFrame.location.href="temp.htm";
instead of:
parent.TextFrame.location="temp.htm";
?
MrDoubtFire
alpine
01-22-2003, 08:40 PM
Well, the problem seems to be that a type=button will update the existing frame. type=submit won't.
No problem to update a different frame.
and I added the .href Thanks.
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.