Results 1 to 6 of 6

Thread: Submitting Form using <Enter> key

  1. #1
    Join Date
    Feb 2009
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Exclamation Submitting Form using <Enter> key

    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!

  2. #2
    Join Date
    Feb 2009
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    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.

  3. #3
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    If you use the get method, things will work out better. Javascript isn't really required:

    HTML Code:
    <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
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  4. #4
    Join Date
    Feb 2009
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    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!

  5. #5
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    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.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  6. #6
    Join Date
    Feb 2009
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Ahh i see what you saying now. Excellent! its working perfectly now. Thanks so much for all your help John.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •