Reputation: 1363
The values of the input fields are not changing. When I alert the variables I get values from the MySQLI database, so there can't be a problem with my php script. Moreover, I've swapped the value() to a css colour and indeed the input fields are all being coloured. So I'm a little confused why it just isn't changing the value to the value of the variables???
Please note the option which triggers the event is one of the options in the drop down menu; that's why I've got to come up tor DOM and then across and it's quite longwinded. I'm new to Jquery btw, so if this can be done in a better way I'll be pleased to hear.
If the HTML is helpful, I've added it below as well
Thank you in advance.
Jquery
$('.option').on('click', function(){
var name = $(this).html();
$.post('ajax.php', {name: name}, function(data) {
var obj = jQuery.parseJSON(data);
var item = obj[6]
var desc = obj[7]
var qty = obj[8]
var price = obj[9]
var disc = obj[10]
var account = obj[11]
var tax = obj[12]
var amount = obj[13]
$(this).closest("td").siblings().eq(0).children().val(item);
$(this).closest("td").siblings().eq(1).children().val(desc);
$(this).closest("td").siblings().eq(2).children().val(qty);
$(this).closest("td").siblings().eq(3).children().val(price);
$(this).closest("td").siblings().eq(4).children().val(disc);
$(this).closest("td").siblings().eq(5).children().val(account);
$(this).closest("td").siblings().eq(7).children().val(tax);
$(this).closest("td").siblings().eq(9).children().val(amount);
});
});
HTML Sample
<td>
<input type="text" name = "sales[1][item]" size = "12">
</td>
<td>
<button class="item" type = "button">Add</button>
<div class = "dropmenu"></div>
</td>
<td>
<input type="text" name="sales[1][description]" size="40">
</td>
Upvotes: 0
Views: 38
Reputation: 33
I would suggest to not use at all the .closest, just like siblings and children. It can make something really simple to something confusing.
you are getting your value and if you can change the colours( as you say you can) then i think your error is somewhere in to "point" exactly to where you want to set your value.
I can't see your full code, try do a simple new element , you may make just for test purposes, and see if it works. IF it does, your failure is really in pointing exactly where you want to set your value.
EDIT: instead of making a new element, just add a class to one of your TD ( or ID) and do
$('.YOUR CLASS').val(WHAT YOU WANNA SET AS VALUE);
Upvotes: 1