solon Posted March 20, 2009 Share Posted March 20, 2009 Hey guys, i have a problem with the combination of ajax php and html form elements.. The problem is the following: Lets say i have a db table with 50 products... i have a while loop that extracts all that data and displays them as shown below: $result = mysql_query("QUERY"); while($row1 = mysql_fetch_array($result)) { <form name='beth' method='post' action='cart.php'> <td> <input type='hidden' id='pid' name='pid' value='$row1[pid]'/> <input type='hidden' id='pname' name='pname' value='$row1[pname]'/> <input type='button' class='remove' value='$row1[price]' onClick='prod_in()' /> </td> </form> } Now the problem is that when i click the button to send those values with ajax to another php file to proccess it and insert the value in the table 'cart' it always gets the first one that is generated. This is the javascript i am using... <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js"></script> <script type="text/javascript"> function prod_in() { $('#sh_gms').load('cart.php',{ 'pname' : $('#pname').val(), 'price': $('#price').val(), 'pid' : $('#pid').val() }); } </script> Any help would be extremely appreciated.. Best Regards, Solon Quote Link to comment https://forums.phpfreaks.com/topic/150289-solved-ajax-php-html-form-elements/ Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.