...

View Full Version : Autofill Form Input Array's in Same Row



macmonkey
07-21-2010, 03:48 AM
I've built a simple order form using input arrays ( input1[], input2[]) and need to autofill some of the TR inputs based on what is entered into the Product # field. I'm close but figuring out how to ONLY autofill the inputs in the same row ignoring elements with the same class in the other rows.


table width="100%">
<tr>
<th>QTY</th><th>PART #</th><th>DESCRIPTION</th><th>MSRP</th><th>COST</th>
</tr>
<tr><td><input type="text" name="qty[]" value="" size="5" /></td>

<td><input type="text" class="partNum" name="part_num" value="" size="7" /></td>
<td><input type="text" class="desc" name="description" value="" size="25" /></td>
<td><input type="text" name="msrp[]" value="" size="5" /></td>
<td><input type="text" class="dealer_price" name="dealer_cost[]" value="" size="5" class="cost" /></td>
</tr><tr><td><input type="text" name="qty[]" value="" size="5" /></td>
<td><input type="text" class="partNum" name="part_num" value="" size="7" /></td>
<td><input type="text" class="desc" name="description" value="" size="25" /></td>
<td><input type="text" name="msrp[]" value="" size="5" /></td>
<td><input type="text" class="dealer_price" name="dealer_cost[]" value="" size="5" class="cost" /></td>
</tr><tr><td><input type="text" name="qty[]" value="" size="5" /></td>
<td><input type="text" class="partNum" name="part_num" value="" size="7" /></td>
<td><input type="text" class="desc" name="description" value="" size="25" /></td>
<td><input type="text" name="msrp[]" value="" size="5" /></td>
<td><input type="text" class="dealer_price" name="dealer_cost[]" value="" size="5" class="cost" /></td>
</tr><tr><td><input type="text" name="qty[]" value="" size="5" /></td>
<td><input type="text" class="partNum" name="part_num" value="" size="7" /></td>
<td><input type="text" class="desc" name="description" value="" size="25" /></td>

<td><input type="text" name="msrp[]" value="" size="5" /></td>
<td><input type="text" class="dealer_price" name="dealer_cost[]" value="" size="5" class="cost" /></td>
</tr><tr><td><input type="text" name="qty[]" value="" size="5" /></td>
<td><input type="text" class="partNum" name="part_num" value="" size="7" /></td>
<td><input type="text" class="desc" name="description" value="" size="25" /></td>
<td><input type="text" name="msrp[]" value="" size="5" /></td>
<td><input type="text" class="dealer_price" name="dealer_cost[]" value="" size="5" class="cost" /></td>
</tr> <tr>
<td colspan="3">&nbsp;</td>
<td>Subtotal</td>
<td><input type="text" name="subtotal" value="" size="5" /></td>
</tr>

</table>



<script type="text/javascript">
$(document).ready(function() {


$(".partNum").bind("change", function() {
var part_num = $(".partNum").val();

$.getJSON("getProductInfo.php?part_num=" + part_num,
function(data)
{
$.each(data,
function(i, item)
{
if(item.field == "description")
{
$(".desc").val(item.value);
} else if (item.field == "dealer_price") {
$(".dealer_price").val(item.value);
}
});
});
});

});
</script>


I figured this could be achieved with $(this).siblings() but it isn't working.

Any help is appreciated.

macmonkey
07-22-2010, 05:35 AM
Well - I didn't get any answer on this but decided to take a different route. I added an id of id="desc_##" and used Javascripts split function to get the id and it all worked out.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum