JavaScript 2級カスケードメニュー
3577 ワード
<html>
<head></head>
<body>
<script>
//
var sx = "[{'levelId':100101,'levelName':' '},{'levelId':100102,'levelName':' '},{'levelId':100103,'levelName':' '}]";
var fw = "[{'levelId':100201,'levelName':' '},{'levelId':100202,'levelName':' '}]";
function changeEmpType(empTypeId){
document.getElementById("level").options.length = 0;
var ob = 0;
// SELECT
if(empTypeId == '1001'){
//
ob = eval("("+sx+")");
}else if(empTypeId == '1002'){
//
ob = eval("("+fw+")");
}
var option = new Option(" ",0);
if(ob != 0){
for(var j in ob){
option = new Option(ob[j].levelName,ob[j].levelId);
document.getElementById("level").options.add(option);
}
}else{
document.getElementById("level").options.add(option);
}
}
</script>
<select name="empType" id="empType" onchange="changeEmpType(this.value)">
<option> </option>
<option value="1001"> </option>
<option value="1002"> </option>
</select>
<select name="level" id="level">
<option> </option>
</select>
</body>
</html>
-----------------------------------------------
<html>
<head></head>
<body>
<script>
// ,sx ,fw
var sx = [{'levelId':100101,'levelName':' '},{'levelId':100102,'levelName':' '},{'levelId':100103,'levelName':' '}];
var fw = [{'levelId':100201,'levelName':' '},{'levelId':100202,'levelName':' '}];
function changeEmpType(empTypeId){
document.getElementById("level").options.length = 0;
var ob = 0;
// SELECT
if(empTypeId == '1001'){
ob = sx;
}else if(empTypeId == '1002'){
ob = fw;
}
var option = new Option(" ",0);
if(ob != 0){
for(var j in ob){
option = new Option(ob[j].levelName,ob[j].levelId);
document.getElementById("level").options.add(option);
}
}else{
document.getElementById("level").options.add(option);
}
}
</script>
<select name="empType" id="empType" onchange="changeEmpType(this.value)">
<option> </option>
<option value="1001"> </option>
<option value="1002"> </option>
</select>
<select name="level" id="level">
<option> </option>
</select>
</body>
</html>