PDA

View Full Version : Submitting Form using <Enter> key



shermernt
02-03-2009, 06:34 PM
Hey all,

I am trying to Submit a form using the Enter Key. As of now, i have an onClick that takes you to a new window and depending on what you put in the field, will filter certain results. here is the code that I have as of now:

<form name="ask" method="post" style="margin-top:-1px;z-index:2;">
<input type="text" id="q" name="q" size="27" value="" maxlength="2047"/><p align="right">
<input name="submit" type="button" value="Ask Now" vspace="3" class="btn" style="margin-right:4px;" onClick="window.location='askquestion.html?q=' + form.q.value">
</form>

the +form.q.value put what ever is in the field and uses that answer in a new window. I tried using an action, it submits but it does put the answer in the new field to active the filter. It basically gives generic results.

Can anyone help?

Thanks!

shermernt
02-03-2009, 08:21 PM
basically I am trying to do something like this but the action is not working at all.

<form name="ask" action="javascript:window.location('askquestion.html?q=' + form.q.value)" method="post" style="margin-top:-1px;z-index:2;">
<input type="text" id="q" name="q" size="27" value="" maxlength="2047"/><p align="left">
<input name="submit" type="button" value="Search Answers" vspace="3" class="btn" style="margin-right:4px; margin-top:5px;" onClick="window.location='askquestion.html?q=' + form.q.value">
</form>

It wont submit the form using <Enter> key.

jscheuer1
02-04-2009, 05:10 AM
If you use the get method, things will work out better. Javascript isn't really required:


<form action="askquestion.html" method="get" target="_blank" style="margin-top:-1px;">
<input type="text" name="q" size="27" maxlength="2047"><p align="left">
<input type="submit" value="Search Answers" class="btn" style="margin-right:4px;">
</form>

This will work onclick of the submit button, or by hitting enter, opening askquestion.html in a new window with the value of q appended as a query string, ex:

askquestion.html?q=whatever

shermernt
02-04-2009, 02:38 PM
Thanks for the reply John,

the ' + form.q.value is needed because whatever someone type in the textfield will be added to the end of the URL which in the results page will be automatically put into another text field which filters the results by what the user had typed. Unfortunately when i only use askquestion.html as my action, it will bring up the results page but it wont filter out the results based on what the user had typed in. It just gives me generic results. Any ideas?

Thanks!

jscheuer1
02-04-2009, 02:54 PM
If you use the get method as outlined in my previous post, it will give you a URL like:

askquestion.html?q=whatever

on the results page. Unless the results page also relies upon post data, this will be the same result as the convoluted javascript approach you've been trying.

If you want more help:

Please post a link to the page on your site that contains the problematic code so we can check it out.

shermernt
02-04-2009, 03:13 PM
Ahh i see what you saying now. Excellent! its working perfectly now. Thanks so much for all your help John.