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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T04:54:22+00:00 2026-05-31T04:54:22+00:00

I have a table which is generated by a php function in which, each

  • 0

I have a table which is generated by a php function in which, each row contains an Action Button which is actually a form containing hidden data. I want to be able so when I click on the action button, data from the hidden input values is passed to an AJAX call.

Here’s what I have so far: (this current code is selecting data from the 1st form no matter if the user clicks on the 2nd form action button)

The Table containing the Forms

<table class="table">
    <thead>
        <tr>
            <th>Card Type</th>
            <th>Name on Card</th>
            <th>Number</th>
            <th>Expires</th>
            <th>CVC</th>
            <th>Action</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td>VISA</td>
            <td>testname testlname</td>
            <td>xxxxxxxxxxxx9999</td>
            <td>12 / 15</td>
            <td>123</td>
            <td>
                <form method="post" class="scc">
                    <input type="hidden" value="VISA" name="scc_ccType1" id="scc_ccType1">
                    <input type="hidden" value="testname testlname" name="scc_ccOwner1" id="scc_ccOwner1">
                    <input type="hidden" value="4444777711119999" name="scc_ccNumber1" id="scc_ccNumber1">
                    <input type="hidden" value="12" name="scc_ccExpiresMt" id="scc_ccExpiresMt">
                    <input type="hidden" value="15" name="scc_ccExpiresYr" id="scc_ccExpiresYr">
                    <input type="hidden" value="123" name="scc_ccCVC1" id="scc_ccCVC1">
                    <input type="submit" value="Select Card" name="select_scc" id="select_scc">
                </form>
            </td>
        </tr>
        <tr>
            <td>VISA</td>
            <td>testname testlname</td>
            <td>xxxxxxxxxxxx1111</td>
            <td>12 / 15</td>
            <td>123</td>
            <td>
                <form method="post" class="scc">
                <input type="hidden" value="VISA" name="scc_ccType1" id="scc_ccType1">
                <input type="hidden" value="testname testlname" name="scc_ccOwner1" id="scc_ccOwner1">
                <input type="hidden" value="4444555566661111" name="scc_ccNumber1" id="scc_ccNumber1">
                <input type="hidden" value="12" name="scc_ccExpiresMt" id="scc_ccExpiresMt">
                <input type="hidden" value="15" name="scc_ccExpiresYr" id="scc_ccExpiresYr">
                <input type="hidden" value="123" name="scc_ccCVC1" id="scc_ccCVC1">
                <input type="submit" value="Select Card" name="select_scc" id="select_scc">
                </form>
            </td>
        </tr>
    </tbody>
</table>

The Jquery Code

<script defer="defer" type="text/javascript">
$(document).ready(function() {
    $("#select_scc").live("click", function() {

        var postData = {
        'authorize'     : 2 ,
        'cc_type'                       : $("#scc_ccType1").val(),
        'cc_number'                     : $("#scc_ccNumber1").val(),
        'cc_expdate_month'              : $("#scc_ccExpiresMt").val(),
        'cc_expdate_year'               : $("#scc_ccExpiresYr").val(),
        'cc_security_code'              : $("#scc_ccCVC1").val(),
        'owner'                         : $("#scc_ccOwner1").val(),

        };

        $.ajax({
                url: "<?php echo base_url().'admin/creditcard';?>",
                type:'POST',
                data: postData,
                dataType: 'json',
                success: function(scard){
                    alert(scard);
                }
        });

        return false;
    });
});
</script>
  • 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-31T04:54:23+00:00Added an answer on May 31, 2026 at 4:54 am

    First off ids need to be unique, so perhaps change the php generating them to add “select_scc” as a class instead.

    Then do somethinbg like this:

    $('submit#select_scc').on('click', function() {
        var $this = $(this); // caches $(this), which is the select_scc element.
    
        // Now to get each value for the form that the user clicked on.
        var postData = {
               'cc_type' : $this.siblings('#scc_ccType1').val(),
               'cc_number' : $this.sibling('#scc_ccNumber1').val(),
               // ........ etc
            };
    
            // now just run the ajax function as you are doing.
    });
    

    Maybe you will have problems with this click function if “select_scc” is not generated when the user clicks, then just bind the function to an element which already is there. For example say everything that is generated is inside a pre-defined div called “#container”, then write the click function like this:

    $('#container').on('click', 'submit#select_scc', function () {
    });
    

    .live is deprecated and just points to the .on function, so just using .on directly will save you some load time.

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

Sidebar

Related Questions

I have a DB table in which each row has a randomly generated primary
I have the following html structure (which is generated and I can't change): <table
I have table which contains double values stored in mysql database ...I need to
I have a table which contains my server status create table ServerStatus ( ServerId
I have a table that has been generated dynamically using PHP. The table has
I have a minor problem, basically I have a hidden input button which is
I have a PHP page which generates an HTML table. At the bottom of
I have a mysql table which will store users email addresses (each is unique
I'm trying to reload a table which was also generated by PHP. The table
I have a small PHP Mysql function which generates all the columns within a

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.