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>