Info

親カテゴリを選択して子カテゴリ決定、子カテゴリ選択してターゲットイベントを実行します。

ポイント
new ActiveXObject(“Scripting.Dictionary”);
new Option(text,value,boolean,boolean);
document.myform.selChild.length=0;

<form name="myform"> 
<select name="selParent" onchange="changeParent();"> 
<option value=""></select> 
<select name="selChild" onchange="changeChild();"> 
<option value=""></select> 
</form> 
<div id="message"></div>        

<script type="text/javascript"> 
<!-- 
var dic = new ActiveXObject("Scripting.Dictionary"); 
dic.Add("言語",new Array(("Java"),("C#"),("C++"),("VB"))); 
dic.Add("Web",new Array(("Html"),("JavaScript"),("ajax"))); 
dic.Add("検索",new Array(("Google"),("Yahoo"),("MSN")));        

onload();        

function onload(){ 
    var p = (new VBArray(dic.Keys())).toArray(); 
    for(i in p){ 
        document.myform.selParent.options[i] = 
            new Option(p[i],p[i],true,true); 
    } 
    document.myform.selParent.options[0].selected=true; 
    changeParent(); 
}        

function changeParent(){ 
    var val = document.myform.selParent.value; 
    var childItem = dic(val); 
    document.myform.selChild.length=0; 
    for (i in childItem){ 
      document.myform.selChild.options[i] = 
         new Option(childItem[i],childItem[i],true,true); 
      document.myform.selChild.options[0].selected=true; 
    } 
    changeChild(); 
}        

function changeChild(){ 
  var message=document.myform.selChild.value; 
  document.getElementById("message").innerHTML = message; 
} 
// --> 
</script>

Comments

No comments yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Basic HTML is allowed. Your email address will not be published.

Subscribe to this comment feed via RSS