Jump to content

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/150289-solved-ajax-php-html-form-elements/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.