Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7030437
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T00:40:14+00:00 2026-05-28T00:40:14+00:00

I have a page with more than one form. One form (see below example)

  • 0

I have a page with more than one form. One form (see below example) has an input to add rows to a table on the page. Each of the rows in the table can be selected (checkbox) on/off. The other form submits the page sending which rows were “on” to the next page.

So, the initial problem was that people were entering a url and clicking return to add it to the table, but instead is was not adding it, but submitting the ‘other’ form (mainForm).

So, I added the jQuery below. That fixed the problem — now, when the url field is in focus and you click return it adds a url to the list and does not submit the mainForm.

However, when that field is NOT in focus, pressing return does nothing – when I expected it to submit the form (the default behavior) … since the event is only attached to that one input field.

HTML (greatly simplified):

<form name="data>
 <input id="url" class="field" type="text" size="65" name="urlText">
 <input class="hubField" type="button" value="Add Url" name="urlAddButton">
 <table>
    <tr>
       <td><input type="checkbox"></td>
       <td>Description text</td>
       ....and so on...
 </table>
</form>

<form name="mainForm">
 <input type="SUBMIT" value="Load Selected Urls" name="Submit">
</form>

JS/jQuery:

$(document).ready(function() {
    $('#url').bind('keyup',function(e) {
        if (e.which == 13) {
        $('input[name="urlAddButton"]').focus().click();
        e.preventDefault();
        }
    })
});

I’m fairly new to jQuery, so be nice. 😉 In js I’d probably just write something saying if that field is not in focus and return is pressed, submit main form. Is there a trick to do this easier in JQuery?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T00:40:15+00:00Added an answer on May 28, 2026 at 12:40 am

    If I understand, you want to submit the mainForm when a user press enter while he’s not in the “url” input. When he’s in, you trigger the click on “urlAddButton”. If so, here is a working example on jsFiddle : http://jsfiddle.net/MUUUE/

    $(document).ready(function(){
        $(this).bind('keydown',function(e) {//keyDOWN (for the input)
            if(e.which == 13) {//if enter is pressed
                if(e.target.id == "url"){//and we're in the url input
                     $('input[name="urlAddButton"]').focus().click();
                     e.preventDefault();
                }
                else if(e.target.type != "textarea" && e.target.type != "text"){//else, we submit the main form (if we're not in another input or textarea)
                    $("#mainForm").submit();//id attr added in the html code
                }
            }
        })
    });
    

    But, in the end, I’m not sure that it’s so good to submit a form while you’re not in an input.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a page which may has about more than 1 form like below.
I have a ASP.NET web application which has more than 100 pages. Each page
I have a page with more than one form. If there was just one
I have more than one form on the same page: I would like to
How can one have more than a Wizard control on the same page without
Basically when I have more than about 25 file uploads in one form, the
I have a JSP page, which accepts user strings in more than 23 languages.
I have the following markup: <p class=managebox> <button value=Add page> <img src=page_add.png alt=Add more
So i have a page that is gonna have multiple modal popups. Each one
I have a form page that has an inputText field that accepts a date.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.