Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    Aug 2004
    Location
    Nashville
    Posts
    202
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Autofill Form Input Array's in Same Row

    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.

    Code:
    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>
    PHP Code:
    <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(
    iitem)
                            {
                                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.

  • #2
    Regular Coder
    Join Date
    Aug 2004
    Location
    Nashville
    Posts
    202
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •