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

  • Home
  • SEARCH
  • 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 8707843
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T03:57:55+00:00 2026-06-13T03:57:55+00:00

I have a problem with a input button insert in a html table and

  • 0

I have a problem with a input button insert in a html table and detecting the pressed button with javascript. All works but, if I alert it in javascript, I can see that it gives me always the element of the first row. Also, if I press the element of the last row.

Now I will explain better with code. In this way I fill the table with the button and all works fine:

//$shows is an array
$size = count($shows);


if ($size != 0) {   
echo "<table class='datatable'>";
echo "<thead>";
echo "<tr>";
echo "<th>ID</th>";
echo "<th>Name</th>";
echo "<th>Language</th>";
echo "<th>Add</th>";
echo "</tr>";
echo "</thead>";
echo "<tbody>"; 
}

for($i = 0 ; $i < $size; ++$i) {

echo "<tr>";
echo "<td>{$shows[$i]->id}</td>";
echo "<td>{$shows[$i]->name}</td>";
echo "<td>{$shows[$i]->language}</td>";
echo "<td>";
echo "<input type='hidden' id='add' value='yes' />";
echo "<input type='hidden' id='seriesid' value={$shows[$i]->id} />";
echo "<input type='hidden' id='lang' value={$shows[$i]->language} />";
echo "<input type='submit' id='name-submit' class='button plain' value='ADD'>";
echo "<div id='add-data'></div>";
echo "</td>";
echo "</tr>";
}


  if ($size != 0) {
  echo "</tbody>";
  echo "</table>";
  }

So in this way, I can see all information in the table and I also see a button for each row. Then I want to detect the button pressed for every row and I have this file in javascript:

$('input#name-submit').click(function() {

    var add = $('input#add').val();
    var seriesid = $('input#seriesid').val();
    var lang = $('input#lang').val();
    alert(lang);
    if ($.trim(add) != '') {

        $.post('AccessDB.php', {add:add, seriesid:seriesid, lang:lang}, function(data) {
            alert(data);
        });
    }

});

Also, in this way I can detect the button pressed and shows me the alert with the lang element, but the lang element is always the element of the first row. If I press the button in the last row (with a different lang element) I see always the element of the first row. If I use the seriesid or the name element for example, it is always the element of the first row. So, how I can detect the other rows also?

  • 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-13T03:57:57+00:00Added an answer on June 13, 2026 at 3:57 am

    You are using same id again and again.Use class instead of class
    use

    echo "<input type='hidden' class='add' value='yes' />";

    instead of

    echo "<input type='hidden' id='add' value='yes' />";
    

    and use this

        var add = $(this).parent().find(".add").val();
        var seriesid = $(this).parent().find('.seriesid').val();
        var lang = $(this).parent().find('.lang').val();
    

    instead of

        var add = $('input#add').val();
        var seriesid = $('input#seriesid').val();
        var lang = $('input#lang').val();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am attempting to insert an input button into an HTML table using .innerHTML
i have the following problem with that code in my html tag: <div id=searchbar><input
I have a minor problem, basically I have a hidden input button which is
all my problem is as follows: I have a page containing an addthis-button. Normally,
I have an input form for a sample php. <form action=insert.php method=post> <table> <tr>
I have the following HTML form <form action=# method=post> <table> <tr> <td><label>Product:<label> <input type=text
I have problem with repopulating form_upload after validation. Other input fields or selectboxes are
I have a problem where I need to split an input string into possible
I have a problem with populating an autocomplete list based on a previous input.
I have little problem in regular expressin creation. Expected input: blahblahblah, blahblahblah, 'blahblahblah', blahblahblah,

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.