Hi guys, I am trying to populate a drop down list when a specific list item is chosen in another drop down using jquery, but for some reason the options are being created outside of the drop down list, here is my code,
function makeModel(obj){
model = new Array();
model[0] = new Array( '212', 'Ace', 'Aceca', 'Cobra', 'Superblower');
model[1] = new Array( '145', '146', '147', '147 3 Door', '147 5 Door', '155', '156', '159', '164', '166', '33', '75', '90', 'Alfasud', 'Alfetta', 'Arna', 'Brera', 'GT', 'GTV', 'Giulietta', 'Gold Cloverleaf', 'Mito', 'SZ', 'Spider', 'Sprint');
model[2] = new Array( 'Rocsta');
var curSel=obj.options[obj.selectedIndex].value ;
var x;
$('#replace').html("<select name=\"test\" id=\"test\">");
for (x in model[curSel])
{
$('#replace').append("<option>" + model[curSel][x] + "</option>");
}
$('#replace').append("</select>");
}
The HTML:
<form>
<fieldset>
<p>
<label for="test">Make: </label>
<select name="test" id="test" onchange="makeModel(this);">
<option>Select one</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>
</p>
</fieldset>
</form>
<div id="replace"></div>
I'm sure it's a logical error somewhere on my part, but I can't find it!
So any help would be appreciated, thanx!