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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T11:07:04+00:00 2026-05-27T11:07:04+00:00

I have a problem creating a button on the fly within its function. I’ve

  • 0

I have a problem creating a button on the fly within its function. I’ve created a table perfectly in php but I don’t know how to create a button inside php code using a function on each button.

Example 
ID              NAME            PRICE               ADD
1               STRAW            100                BUTTON 1
2               STRAWRE          300                BUTTON 2
3               STRAWTO          200                BUTTON 3

The button add is dynamically using looping inside the html table. and when I process a click on the button, then the id, name, and price item will be changed with the textbox and each textbox has an auto value using the old one, and button 1 will be added one button left button 1, or button 2, or button 3.

function cetakdata()
{
    if(is_array($_SESSION['pembelian']))
    {
    $total = "";
    echo "Here's your chart" . "<br>";
    $max = count($_SESSION['pembelian']);  
    $th1 = "<th>" . "No" . "</th>";
    $th2 = "<th>" . "Nama Barang" . "</th>";
    $th3 = "<th>" . "Harga Barang" . "</th>";
    $th4 = "<th>" . "Jumlah" . "</th>";
    $th5 = "<th>" . "Subtotal" . "</th>";
    $th6 = "<th>" . "Add Edit" . "</th>";
    echo "<table border=1>";
    echo "<tr>";
    echo $th1 ;
    echo $th2;
    echo $th3;
    echo $th4;
    echo $th5;
    echo $th6;

    echo "</tr>";
    for ($indexo = 0; $indexo < $max; $indexo++) {
   echo "<tr>";
   echo "<td>" . $indexo."</td>";
   echo "<td>" . $_SESSION['pembelian'][$indexo]['namabarang']."</td>";
   echo "<td>" . $_SESSION['pembelian'][$indexo]['hargabarang']."</td>";
   echo "<td>" . $_SESSION['pembelian'][$indexo]['jumlahbarang']."</td>";
   echo "<td>" . $_SESSION['pembelian'][$indexo]['subtotal']."</td>";
   echo "<td>" .THIS IS HOW I PUT THE BUTTON ON THE FLY DELETE BUTTON."</td>";
    $total += $_SESSION['pembelian'][$indexo]['subtotal'];
   echo "</tr>";
    }
    echo "TOTAL BELANJA = ". $total;
    echo "</table>";
    }else
    {
        echo "Chart is still Empty";
    }
}

This is the code. When the button created I the other td will be changing into textbox with its value and after user finished edit user can also save it within the save button beside the add button but the save button will be appeared when user click on edit button like the image above :

enter image description here

  • 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-27T11:07:05+00:00Added an answer on May 27, 2026 at 11:07 am

    just add like a normal button in the last td

    <button id="1" name="button">BUTTON 1</button>
    

    and for action do with some jquery function

    $(function(){
        $('button[name=button]').click(function(){
            var id= $(this).attr("id");
            //some action here
            //ex:
            window.location.href="ex.php?id="+id;
            //or an ajax fungtion
        });
    });
    

    oh… may be you can do with this

    <script>
    $(function(){
        $('button[name=button]').click(function(){
            var id= $(this).attr("id");
            //some action here
            //ex:
            window.location.href="ex.php?id="+id;
            //or an ajax fungtion
        });
    });
    </script>
    <?php
    $query = mysql_query("select * from barang");
    echo '<table><tr><th>Nama Barang</th><th>Harga Barang</th><th>Stok</th><th>Action</th></tr>';
    while($data = mysql_fetch_array($query)){
        echo "<tr>
            <td>".$data['nama_barang']."</td>
            <td>".$data['harga_barang']."</td>
            <td>".$data['stok_barang']."</td>
            <td><button id=".$data['kode_barang']." name=\"button\">Edit</button></td>
        </tr>";
    }
    echo '<table>';
    ?>
    

    EDITED

    changes this
    <td><button id=".$data['kode_barang']." name=\"button\">Edit</button></td>

    to

    <td><button id=".$data['kode_barang']." name=\"button\" style=\"display:none\">Edit</button><button id=".$data['kode_barang']." name="..$data['kode_barang'].">Edit2</button></td>

    and on the javascript just add modify just like this

    $(function(){
        $('button[name=button]').click(function(){
            var id= $(this).attr("id");
            $("button[name="+id+"]").show();
            //some action here
            //ex:
            window.location.href="ex.php?id="+id;
            //or an ajax fungtion
        });
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a problem in creating a Button with text and image on it.
I have a slight problem with creating a button on the server side code.
im creating a like system but i have ran into a problem, with when
I have problem with handling dynamically created Buttons on Android. I'm creating N buttons
I have a problem in creating an AJAX-based form submission which if its response
I have problem creating new instance of excel 2007 using VBA (from Access 2002).
I have problem with creating a simple MySQL trigger in C#. I'm using StringBuilder
I have an irritating problem, I'm creating an asp.net web service; this service should
i have a small problem, i am creating a edit page in my asp.net
I have run into a strange problem, i am creating a lot of dynamically

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.