A way to realize two select linkage

Source: Internet
Author: User
Tags naming convention

I wrote it for my friend today. Linkage of the way there are many, write this when the main consideration, so that the server to do more work, as an example test method only 6 lines of code, the speed of the browser should be very fast, but also does not occupy the browser's memory, the most recent writing JavaScript, often encountered performance problems, So, from now on, pay attention.

The following code is simpler, actually relies on a naming convention and the method of cloning objects, cloning is not necessary, but I think it is true. If the volume of data can not be cloned directly hidden display can be, the background to do a simple logical judgment. < HTML >
< head >
< script type = "Text/javascript" >
function $ (ID) {
return document.getElementById (ID);
}
function Test () {
var echild = $ (' child_ ' + $ ("parent"). Value). CloneNode (True);
Echild.name = "Child";
EChild.style.display = "";
Echild.value = "C2"
$ ("Cspan"). InnerHTML = "";
$ ("Cspan"). AppendChild (Echild);
}
function init () {
Test ()
}
</script >
< body onload = "init ();" >
<%= Request.getparameter ("child")%>
< form method = "POST" >
< SELECT id = "Parent" onchange = "test ();" >
< option value = "1" > a </option >
< option value = "2" > B </option >
< option value = "3" > C </option >
</Select >
< span id = "CSPAN" ></span >
< SELECT id = "Child_1" style = "display:none;" >
< option value = "C1" > ca_a </option >
< option value = "C2" > cb_a </option >
< option value = "C3" > cc_a </option >
</Select >
< SELECT id = "Child_2" style = "display:none;" >
< option value = "C1" > ca_b1 </option >
< option value = "C2" selected > cb_b2 </option >
< option value = "C3" > cc_b3 </option >
</Select >
< SELECT id = "Child_3" style = "display:none;" >
< option value = "C1" > Ca_c </option >
< option value = "C2" > Cb_c </option >
< option value = "C3" > Cc_c </option >
</Select >
< input type = "Submit"/>
</form >
</Body >
</HTML >

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.