Code for passing values between javascript select statements

Source: Internet
Author: User

Passing the values in the two boxes has good results.

Copy codeThe Code is as follows:
<Script type = "text/javascript" defer = "defer">

Function $ (value)
{
Return document. getElementById (value );
}
Function ch (s ){
Var p = new Array (0, 1, 2 );
P [0] = '';
P [1] = 'high school ';
P [2] = 'Junior high school ';
If (s. value = '0 '){
$('N2 '). options. length = 0;
$('N2 '). options. add (new Option (p [0], p [0]);
}
If (s. value = '1 '){
$('N2 '). options. length = 0;
$('N2 '). options. add (new Option (p [1], p [1]);
}
If (s. value = '2 '){
$('N2 '). options. length = 0;
$('N2 '). options. add (new Option (p [2], p [2]);
}
}
</Script>
<Table width = "400" border = "0" align = "center" cellpadding = "0" cellspacing = "0">
<Tr>
<Td width = "119"> <select name = "n1" size = "10" id = "n1" onchange = "ch (this)">
<Option value = "0"> university </option>
<Option value = "1"> high school </option>
<Option value = "2"> Junior High School </option>
</Select>
</Td>
<Td width = "281"> <select name = "n2" size = "10" id = "n2"> <option value = "a"> a </option>
</Select> </td>
</Tr>
</Table>


<Table width = "400" border = "0" align = "center" cellpadding = "0" cellspacing = "0"> <tr> <td width = "119"> <select name = "n1" size = "10" id = "n1" onchange = "ch (this) "> <option value =" 0 "> university </option> <option value =" 1 "> high school </option> <option value =" 2 "> Junior High School </option> </select> </td> <td width = "281"> <select name = "n2" size = "10" id = "n2"> <option value =" a "> a </option> </select> </td> </tr> </table>
[Ctrl + A select all Note: If you need to introduce external Js, You need to refresh it to execute]

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.