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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T16:16:42+00:00 2026-05-20T16:16:42+00:00

Ok: i have a dynamic form like this: <div id=container> <div id=autosuggest>…</div> <form action=

  • 0

Ok: i have a dynamic form like this:

<div id="container">
<div id="autosuggest">...</div>
<form action="" method="post" id="inputForm">
    <table>
        <thead>
            <tr>
                <th>amount</th>
                <th>name</th>
                <th>discount</th>
                <th>vat</th>
                <th>price</th>
                <th>comment</th>
                <th>&nbsp;</th>
            </tr>
        </thead>
        <tbody>
            <tr id="row1">
                <td><input type="text" name="amountRow1" id="amountRow1" value=""/></td>
                <td>Product name 1 </td>
                <td><input type="text" name="discountRow1" id="discountRow1" value=""/></td>
                <td>
                    <select id="vatRow1" name="vatRow1">
                        <option value="10">10%</option>
                        <option value="20">20%</option>
                        <option value="30">30%</option>
                    </select>
                </td>
                <td><input type="text" name="priceRow1" id="priceRow1" value=""/></td>
                <td><input type="text" name="commentRow1" id="commentRow1" value=""/></td>
                <td><button class="trashButton"></button>
            </tr>
            <tr id="row2">
                <td><input type="text" name="amountRow2" id="amountRow2" value=""/></td>
                <td>Product name 2 </td>
                <td><input type="text" name="discountRow2" id="discountRow2" value=""/></td>
                <td>
                    <select id="vatRow2" name="vatRow2">
                        <option value="10">10%</option>
                        <option value="20">20%</option>
                        <option value="30">30%</option>
                    </select>
                </td>
                <td><input type="text" name="priceRow2" id="priceRow2" value=""/></td>
                <td><input type="text" name="commentRow2" id="commentRow2" value=""/></td>
                <td><button class="trashButton"></button>
            </tr>
        </tbody>
    </table>
    <input type="submit" id="submitForm" name="submitForm" value="submit">
</form>

some things to clarify:

  1. Each row is different from another by a unique timestamp, in this example simplified as row1, row2, etc…
  2. The container div is actually a div which is placed in a jquery-ui-dialog
  3. The autosuggest div has some other stuff in it needed for a simple autosuggest
  4. Each row is dynamically added using the autosuggest, keeping each row unique using the timestamp
  5. Each row has a button with class=’trashButton’ which is a jquery-ui-button, the obvious purpose of the button is to remove the row from the table.
  6. There is no action value specified for the form since the form is handled with an ajaxcall

The button eventhandler:


$(document).ready(function(){
    $(".trashButton").live('click', function(){
        removeProduct(this);
        return false
    });
})

Now the issue is the following:

When my cursor is in any input field in the table, and i press the enter button. The first row gets removed from the table. No matter where the focus/cursor is at the time, its always the first row that gets removed.
The fact is, there shouldnt be ANY row removed on pressing the enter button. Instead if anything should happen at all, the form should try to submit.
On the other hand, when my cursor/focus is in the autosuggest inputfield and i press enter: nothing happens, which is exactly what i wanted.
When i click the ‘trashButton’ the correct row DOES get removed: also how it’s supposed to work.

I’ve debugged all i could think of which could cause the problem concerning the autosuggest plugin or wrong closing tags or anything simple and alike (what i mean is, i’ve debugged most obvious things i could think of).

So in short: i have no idea as to why my removeProduct() get’s triggered at all, or,even worse, having it delete the first row all the time instead of the actually focussed row(which would make more sense). I’m not really sure how to capture the triggered eventhandler when i press the enter button so i have no clue how to debug this.

All help or suggestions would be much appreciated,

Cheers,

Bodybag

edit:

@Ed Fryed:
Thank you for the quick reply. Problem solved! Changed the button into an anchor which made the enterpress trigger the formsubmit. Cancelled the form submit using preventDefault(). But now i got the submit function cancelled for every form using the following:

$("#inputForm").keypress(function(event){
   if(event.which===13){
       event.preventDefault();
    }
})

Vote would be granted if i had more rep xD
Btw help on the new issue would be more then lovely,

cheers bodybag

  • 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-20T16:16:43+00:00Added an answer on May 20, 2026 at 4:16 pm

    I could be wrong but when dealing with forms pressing the enter button triggers the first button in the form. In your case the first button encountered is the trash button to the first row.

    two options.

    first(and the one i would choose)

    make your trash buttons a div or link or some other element. as they dont actually need to be buttons.

    second.
    if they really have to be buttons then you will have to detect enter being pressed and stop its default.

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

Sidebar

Related Questions

I would like to make this form dynamic with prototype. I mean, the radio
i have a javascript function like this: function addfamily(divName){ var newdiv = document.createElement('div'); newdiv.innerHTML
I have a couple of tables with similar structures like this: <table> <tbody> <tr>content</tr>
I have a form like this: <form id=cform> <label>folder name:</label> <input type=text name=Folder[name] />
I have a web form that I am attempting to implement dynamic drop down
I have a dynamic class that serves as a storage container for configuration settings.
I have a custom built ajax [div] based dynamic dropdown. I have an [input]
I have a form containing some dynamic elements. These are basically text input boxes
I have a rwrite rule which is like this: RewriteRule ^30/edit-print-ready-vinyl-banners.html edit_print_ready_form.php?id=30 Now I
I am new in jQuery and I have to do a dynamic form with

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.