Js uses the form select class to implement cascading menu Effects

Source: Internet
Author: User

Use Cases:
Copy codeThe Code is as follows:
<Form name = "form1" method = "POST" action = "-- WEBBOT-SELF --">
<Select id = "select1" onchange = "select1onchange ()">
<Option value = "1"> 1 </option>
<Option value = "2"> 2 </option>
<Option value = "3"> 3 </option>
<Option value = "4"> 4 </option>
</Select>
</Form>

We recommend that you set the value of each option to indicate which option the user selects.
Use document. getElementById ("select1"). value; or form1.select1. value in javascript;
Then you can obtain the selected value.
The onchange event is triggered when the select option value is changed.

When using cascading menus
Create two select statements whose IDs are select1 and select2.
Create the trigger function javascript function for select1, select1onchange (). In this function, obtain the value of select1,
Check the table to obtain the corresponding select2 value, and add corresponding options for select2 to achieve cascade effect.
Copy codeThe Code is as follows:
<Select id = "select1" onchange = "select1onchange ()">
<Option value = "1"> 1 </option>
<Option value = "2"> 2 </option>
<Option value = "3"> 3 </option>
<Option value = "4"> 4 </option>
</Select>
<Select id = "select2" onchange = "select2onchange ()">
</Select>
Function t1onfocus ()
{
Document. getElementById ("p1"). innerHTML = "Get Focus ";
}
Function select1onchange ()
{
Var I;
For (I = 10; I> = 0; I --)
Form1.select2. remove (I );
Var objOption;
For (I = 0; I <= 9; I ++)
{
ObjOption = document. createElement ("OPTION ");
ObjOption. text = form1.select1. value * 10 + I;
ObjOption. value = form1.select1. value * 10 + I;
Form1.select2. options. add (objOption );
}
}
Function select2onchange ()
{
P1.innerHTML = form1.select2. value; // p1 is the custom item used for output in the document.
}

Related Article

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.