I have two boboxs.i want to set second bobox values on the basis of first bobox values on change.like if i three values (1,2,3) for first one and on select 1 i populate second one with values (11,12,13) and same for others.I can do it in php but don't know how to do it in js or jquery.Thanks
I have two boboxs.i want to set second bobox values on the basis of first bobox values on change.like if i three values (1,2,3) for first one and on select 1 i populate second one with values (11,12,13) and same for others.I can do it in php but don't know how to do it in js or jquery.Thanks
Share Improve this question asked Mar 17, 2014 at 18:26 AddaAdda 3055 silver badges18 bronze badges1 Answer
Reset to default 4Here is how you can do this:
JavaScript
var first = document.getElementById('select-input'),
second = document.getElementById('second-select-input');
first.onchange = function (e) {
var val = e.target.value;
empty(second);
for (var i = 0; i < 3; i += 1) {
addOption(val + '' + (i + 1), second);
}
};
function empty(select) {
select.innerHTML = '';
}
function addOption(val, select) {
var option = document.createElement('option');
option.value = val;
option.innerHTML = val;
select.appendChild(option);
}
HTML
<select id="select-input">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>
<select id="second-select-input">
</select>
DEMO
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745649579a4638179.html
评论列表(0条)