I am stuck with this.. and I am new also so not really promising. I have a html table that is being populated using php and mysql. Each row has 4 columns, one of the columns is a ‘update’ button with the follwoing syntax
print("<input type='submit' value='Update' name='update' class='submit_button'/>");
now, the class=’submit_button’ is new as i added per a suggestion in a related question using json and the function is here
$( '.submit_button' ).click( function(){
var value = {};
$( this ).closest( '.submit_button' ).find( 'input, select' ).each(function(){
value[ $(this).attr('name') ] = $(this).val();
});
$.post( "test.php",
value,
function(data){
//success
alert( data );
},
"json"
);
});
I was expecting to see the alert saying it posted or something… but nothing… Now I also tried adding a form to the row.. but that did not work either. Here is my full html table
print("<table id='results'><tr><th>ID</th><th>Image</th><th>Name</th><th>Price</th><th>Price Label</th><th>Description</th><th>Update</th></tr>");
while($row2 = mysql_fetch_array( $result2 )){
$client_id = $row2["client_id"];
$client_name = $row2["client_name"];
$client_disc = $row2["client_disc"];
$client_price = $row2["client_price"];
$client_image = $row2["client_image"];
$client_price_label = $row2["client_price_label"];
print("<tr>");
print("<td>");
print("<p style='font-size:14px; color:blue; padding:0;'>$client_id</p>");
print("</td>");
print("<td>");
print("<img class='custom_rate' alt='' src='$client_image' />");
print("</td>");
print("<td width='100px'>");
print("<input type='text' value='$client_name' name='clientname'/>");
print("</td>");
print("<td>");
print("<input type='text' value='$client_price' name='clientprice'/>");
print("</td>");
print("<td width='100px'>");
print("<input type='text' value='$client_price_label' name='clientpricelabel'/>");
print("</td>");
print("<td width='100px'>");
print("<textarea cols='15' rows='2' name='description'>$client_desc</textarea>");
print("</td>");
print("<td width='100px'>");
print("<input type='submit' value='Update' name='update'/>");
print("</td>");
print("</tr>");
}
print("</table>");
So i am not sure how to make this work, if you could help me elaborate on the json way.. or if there is another way… I was thinking maybe something simpler.. How can I just click on the update button and get the values and store them somewhere in the same page where i can use them, and then i will pass those values to php variables and do my update?
Thank you for the patience
It’s a submit button so it is submitting your page before the Javascript has a chance to run.
Try a regular type=”button” and see if that works.