Jump to content

Populating One Select Box Based on Another When Selects are Arrays


DBookatay
Go to solution Solved by 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>
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.