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 8281577
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T10:04:55+00:00 2026-06-08T10:04:55+00:00

I have two different input fields with their own respective submit buttons and I

  • 0

I have two different input fields with their own respective submit buttons and I want the user to be able to enter their input into either of the text boxes and then hit the enter key and have the same effect as if they were to click on the submit button. Currently, typing something into the text box and hitting the enter key does nothing. I’m using HTML and JavaScript and ASP .NET MVC3. My code looks like this:

The HTML

<table>
<tr>
    <td><span class="labelText">Text1</span></td> <td><input id="text1" type="text" placeholder="Enter Text1"/> </td> <td style="width: 110px; text-align: left; margin-left: 5px"><button class="medium awesome blue" id="sendText1">Send Text1</button></td>
</tr>
<tr>
   <td> <span class="labelText">Text2</span> </td> <td><input id="text2" type="text" placeholder="Enter Text2"/> </td>   <td style="width: 110px; text-align: left; margin-left: 5px"> <button class="medium awesome blue" id="sendText2">Send Text2</button> </td>
</tr>

The JavaScript

$('#sendText1').click(function () {
        $('#text2').val("");
        var text1 = $("#text1").val();
        $('#loadingUsageInfo').css({ 'visibility': 'visible' });
        if (text1 == "" || text1 == 'Enter Text1') {
            alert('Enter Text First');
            return;
        }
        $.ajax({
            url: '@Url.Action("ShowResult1", "Folder")',
            type: 'POST',
            contentType: 'application/json; charset=utf-8',
            data: JSON.stringify({ input1: text1 }),
            traditional: true,
            success: function (result) {
                $('#info').html(result);
            }
        });
    });

    $('#sendText2').click(function () {
        $('#text2').val("");
        var text2 = $("#text2").val();
        $('#loadingUsageInfo').css({ 'visibility': 'visible' });
        if (text2 == "" || text2 == 'Enter Text2') {
            alert('Enter Text First');
            return;
        }

        $.ajax({
            url: '@Url.Action("ShowResult2", "Folder")',
            type: 'POST',
            contentType: 'application/json; charset=utf-8',
            data: JSON.stringify({ input2: text2 }),
            traditional: true,
            success: function (result) {
                $('#info').html(result);
            }
        });
    });

Thanks in advance!

  • 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-06-08T10:04:58+00:00Added an answer on June 8, 2026 at 10:04 am

    Add this below your js code

    $('#text1, #text2').keypress(function(e) {
      if (e.which == 13) {
        $('#sendText1, #sendText2').trigger('click');
      }       
    }​​​​​​);
    

    Trigger – Executes all handlers and behaviors attached to the matched elements for the given event type.

    So we’re binding both text inputs on keypress and calling all bindings for the buttons.

    Also see how that works on the jsFiddle

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

Sidebar

Related Questions

I have two different buttons on my page. I want them both to be
I have two different arrays, one with strings and another with ints. I want
I currently have two input fields which toggle the value value to either true
I want to use a form that has two submit buttons. Each button calls
I have two logical groups of input fields I need to validate separately using
I have two things i want to do to this input text field. <input
for email validation I have these two input fields: <input class=inputbox type=text name=data[subscriber][email] id=field_email
I have a form with an input box where user can specify their names,
I have a form with an input box where the user can specify their
On our login page, we have two input fields (username and password), but the

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.