Learn the work of JS-----N-Level linkage select Drop-down box

Source: Internet
Author: User
Js|select| pull Down


<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">

<meta http-equiv= "Content-type" content= "text/html; charset=gb2312 "/>
<title> Small Grey </title>

<body>

<form name= "Form1" method= "POST" >
<select id= "S1" name= "S1" ></select><select id= "s2" name= "s2" ></select><select id= "S3" Name= "S3" ></select><select id= "S4" Name= "S4" ></select>
</form>
<script language= "JavaScript" >
<!--
function Liandong (arr, sel)
{
var me = this;
this.$ = function (o)
{
return document.getElementById (o);
}

This.sub = function (i, PID)
{
for (var j=i+1; j<sel.length; J + +)
{
me.$ (Sel[j]). length = 0;
me.$ (Sel[j]). options[0] = new option ("Please select", "");
}
for (var j = 0; J < Arr.length; J + +)
{
if (arr[j][1] = = pid)
{
me.$ (Sel[i+1]). options[me.$ (Sel[i+1]). length] = new Option (arr[j][2), arr[j][0]);
}
}
}

This.init = function ()
{
Me.sub ( -1, "root");
for (var i=0; i<sel.length-1; i++)
{
me.$ (Sel[i]). onchange = function ()
{
var i;
For (i=0 me.$ (sel[i))!=this; i++);
Me.sub (i, me.$ (Sel[i]). Value);
}
}
}

This.init ();
}

var array=new array ();
Array[0]=new Array ("South China", "root", "South China");
Array[1]=new Array ("North China", "Root", "North China");
Array[2]=new Array ("Shanghai", "South China", "Shanghai");
Array[3]=new Array ("Guangdong", "South China", "Guangdong");
Array[4]=new Array ("Xujiahui", "Shanghai", "Xujiahui");
Array[5]=new Array ("Phut", "Shanghai", "Phut");
Array[6]=new Array ("Guangzhou", "Guangdong", "Guangzhou");
Array[7]=new Array ("Zhanjiang", "Guangdong", "Zhanjiang");
Array[8]=new Array ("Zhanjiang 1", "Zhanjiang", "Zhanjiang 1");
Array[9]=new Array ("Zhanjiang 2", "Zhanjiang", "Zhanjiang 2");
Array[10]=new Array ("Guangzhou 1", "Guangzhou", "Guangzhou 1");
Array[11]=new Array ("Guangzhou 2", "Guangzhou", "Guangzhou 2");

var select = new Array ("S1", "S2", "S3", "S4");

var liandong=new liandong (array, select)
-->
</script>

</body>



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.