0

I am writing a programme i am printing from mysql with php in a table i want to get input field value by the help of jquery how can i get each input value using jquery.

<?php
$sql = "SELECT id, name, price, qty FROM appetisers";
$result = mysqli_query($conn, $sql);

if (mysqli_num_rows($result) > 0) {
    // output data of each row
    while($row = mysqli_fetch_assoc($result)) { 
         $quantity = $row["qty"]; 
         if ($quantity == '' || $quantity == '0') {
              $quantity = '1';
           }  

        ?>
        <tr class="eachrow">
            <td><?php echo $row["name"] ?></td>
            <td class="price-amount">£ <?php echo $row["price"] ?></td>
            <td><input type="text" name="amount" class="amount-type" value="<?php echo $quantity; ?>"/></td>
            <td><a href="" class="add-cart">Add to cart</a></td>
        </tr>
    <?php }
}
?>
MillaresRoo
  • 3,808
  • 1
  • 31
  • 37
hasan
  • 55
  • 6
  • possible duplicate of [Obtain form input fields using jQuery?](http://stackoverflow.com/questions/169506/obtain-form-input-fields-using-jquery) – Dallin Dec 19 '14 at 12:40

5 Answers5

1

Try this:

$('.add-cart').click(function(e){
    var val = $(e.target).closest('.eachrow').find('[ name="amount"]').val();
   console.log(val);
})
Indranil Mondal
  • 2,799
  • 3
  • 25
  • 40
0

Firstly you'd need to give you inputs some sort of identifyer for example add and increment so your inputs can have id's such as 'appetisers_' . $increment

Then you can get these with jquery and get the value using

$('#appetisers_3').val();

At the moment you have a name on the inouts, but they will all have the same name

atmd
  • 7,430
  • 2
  • 33
  • 64
0

By using Jquery val() you can get the value of text field like this

var Values = $( ".amount-type" ).val();

i think it will work fine

Amit Mishra
  • 291
  • 3
  • 12
0

Try this

$('.amount-type').each(function() {
    console.log( this.val() );
});
Rahul Vyas
  • 221
  • 7
  • 18
0
  <script> 
   var TableData = new Array();
    $('table tr.eachrow').each(function(row, tr){
        TableData[row]={
                    "amount" : $(tr).find('td:eq(2)').val()
            }
    }); 
    TableData.shift();
 </script>
Pankaj katiyar
  • 464
  • 10
  • 26