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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T06:06:22+00:00 2026-06-11T06:06:22+00:00

I have this markup. <form action=’xxx.php’ method=’post’> <table> <tr> <th>Branch Id</th> <td><input id=branchId type=text

  • 0

I have this markup.

   <form action='xxx.php' method='post'>
      <table>
        <tr>
            <th>Branch Id</th>   
            <td><input id="branchId" type="text" size="15%" name="branchId"></input></td>
         <th>Branch Name</th>
          <td colspan="3"><input id="branchName" type="text" size="75%" name="branchName"></input></td>
            <td>
                <div id="button">
                <input type="button" id="btnAdd" value="Add" name="submit"/>
                </div>
             </td>
         </table>
     </form>


     <!------- Something here--------------->

     <table class="divTable" id="exisBranch">
       <tr><th id="thBranchId">Branch Id</th>
       <th id="thBranchName">Branch Name</th>
       <th class="btn" id="tcEdit">Edit</th>
               <th class="btn" id="tcDelete">Delete</th>
       </tr>

</table>

What basically happens is I populate the second table records retrieved through AJAX. Each row has a ‘branchId’,’branchName’ and two buttons of class ‘bt’. When I click the edit button, I need the corresponding ‘branchId’ and ‘branchName’ values inserted into input elements in the first table, so that I can edit them and later, when I click the “btnAdd”, I can save them.

This is the jQuery I have.

       function fun(){
                 var branchId=$(this).closest("tr").find("td").eq(0).html();
                 $("#btnAdd").click(function () {
        if($("#btnAdd").val()=='Save')
            {
              alert(branchId);
                          //ajax call

            }

       });
       }


       $(document).ready(function(){
            $("#exisBranch").on('click','.bt',fun);
            $("input[type='button']").click(function(e){
                   e.preventDefault();
            });    
       });

Everything works fine when I click the ‘btnAdd’ for the first time. The problem starts with the second and successive clicks on this button.Consider that there are 6 rows in the dynamically populated content, and that ‘branchId’ of each row is the corresponding row number.

When I first click on ‘EDIT’ button on the 2nd row, and then the ‘btnAdd’, an alert correctly pops up showing 2.

Problem is , if I then go on to click ‘EDIT’ on the 6th row, and then the ‘btnAdd’ , I get two alerts. The first one shows 2, then 6.I just want 6.

For the third round, it goes like 2,6, and what ever is clicked next. This is making my AJAX fire as many no. of times as the no. of clicks.

This is really infuriating.I just can’t seem to figure out why. I am a jQuery novice, so please bear with me if this is something fundamental and I messed it up.Please let me know how to make it fire only once with the latest value, instead of it stacking up on my history of calls?

  • 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-11T06:06:24+00:00Added an answer on June 11, 2026 at 6:06 am

    You shouldn’t keep binding your Add button w/ each Edit click–move it out to your document ready.

    <script>
       var branchId; //keep track of which branch is under edit
    
       function fun(){
          branchId = $(this).closest("tr").find("td").eq(0).html();
          var branchName = $(this).closest("tr").find("td").eq(1).html();
    
          $('#branchId').val(branchId);
          $('#branchName').val(branchName);
       }
    
       $(document).ready(function(){
          $("#exisBranch").on('click','.btn',fun);
    
          $("#btnAdd").click(function () {
             if($("#btnAdd").val()=='Save') {
                alert(branchId);
                //ajax call
             }
          });
    
          $("input[type='button']").click(function(e){
             e.preventDefault();
          });
       });
    <script>
    

    *you have a number of typos in your stack post.

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

Sidebar

Related Questions

This is my markup: <form action=/Customer/Create enctype=multipart/form-data method=post> <input id=file type=file style=width:300px /> <input
i have the following markup <form method=post action= id=form_1> <input type=hidden name=night[] value=1311976800/> <input
Let's say I have markup like this: <form action=foo> <input name=bar /> <button type=button>Save</button>
I have this markup: @using (Html.BeginRouteForm(Default, new { controller = Home, action = Form
I have this form: Markup is: <table style=width: 100%; padding:5px;> <col style=width: 20%; text-align:
I have a form with markup like this.... Which voucher did you cut out
I have a simple form and inside there are two input fields text type.
I have HTML stored in a string. The markup contains form input fields called
After doing so: $.ajax({ type: POST, url: $(#form).attr(action), data: value= + value + &sel=
i have this markup <div class=pfbc-form id=ticker_div style=padding: 0px; line-height: 18px; width: 64%; margin-top:

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.