Jump to content

Populating One Select Box Based on Another When Selects are Arrays


DBookatay

Recommended Posts

I know how to populate one select box based on the option from another using jquery and ajax, but how do you do it when the select boxes are arrays?

By default there are 10 rows on the page, however I also am using .EnableMultiField() to add more lines as I need them... On any given week we add between 10 to 30 vehicles into our inventory.

Ajax:

 

$(".make").change(function() {
var id=$(this).val();
var dataString = 'id='+ id;

$.ajax ({
    type: "POST",
    url: "get_models.php",
    data: dataString,
    cache: false,
    success: function(html) {
        $(".model").html(html);
    } 
});

});

 

And the php

<ul>
   <li>Year <select name="year[]"><option></option>'.$Year.'</select></li>
   <li>Make <select name="make[]" class="make"><option></option>'.$Make.'</select></li>
   <li>Model <select name="model[]" class="model" style="width: 120px"><option></option>'.$Model.'</select></li>
   <li>Trim <input type="text" size="10" name="trim[]" /></li>
   <li>VIN <input type="text" name="vin[]"size="20" maxlength="17" onkeyup="return Upper(event,this)" /></li>
   <li>Mileage <input type="text" name="mileage[]" size="3" maxlength="6" /></li>
   <li>Color <select name="color[]"><option></option>'.$Color.'</select></li>
   <li>Cost <input type="text" name="cost[]" size="6" maxlength="6" onchange="currency(this)" /></li>
   <li>Asking <input type="text" name="asking[]" size="6" maxlength="6" onchange="currency(this)" /></li>
</ul>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.