Ajax to read from form
        Posted  
        
            by Edwin
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by Edwin
        
        
        
        Published on 2010-05-15T21:57:32Z
        Indexed on 
            2010/05/15
            22:02 UTC
        
        
        Read the original article
        Hit count: 182
        
Hello,
I'm writing a store system for my game, it worked quite well until I found out that it only takes the amount of first entered Item.
function pbuy(buyitem) {
 var amountc = "amount-"+buyitem,
 var amount = $("#"+amountc+"").val();
   $.ajax({
   type: "POST",
   url: "store2.php",
   data: "buyitem="+ buyitem+"&amount="+amount,
   success: function(resp){
   document.getElementById('ajaxDiv').innerHTML =  resp;
},
   error: function(e){
     alert('Error: ' + e);
   }
 });
}  
I'm trying to give it it the Id of the form like so:
function pbuy(buyitem) { var amountc = "amount-"+buyitem, var amount = $("#"+amountc+"").val();
But nothing happens.
The code the creation of the forms is:
<tr> <td class='items' width='80%' align='center' valign='top'><?PHP echo $itemstore->itemname;?> </td> <td width="20%">  Price:<?PHP echo $itemstore->newprice;?>          <form  method="post"> <input type='text' id='amount-<?PHP echo $row;?>)' />   <input name="itembid" type="button" onclick="pbuy(<?PHP echo $row;?>)"  value="Buy" /></form></td> </tr>
If I hardcode the amount in the ajax function it all runs fine like it should.
© Stack Overflow or respective owner