Interaction between dropdownlist (display and hide)

Source: Internet
Author: User

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

Var Arrchange1 = new Array ();
Var Arrchange2 = new Array ();
Var Arrchange3 = new Array ();
Function hide (s_id, index)
{
Var xxx = document. getElementById (s_id );
Var oldOption = xxx. children (index );
Var oldStr = oldOption. innerText;
Var newOption = document. createElement ('<div' + oldOption. outerHTML. match (/(<\ w *) ([^>] *) (>)/) [2] + '> ');
NewOption. innerText = oldStr;
NewOption. swapNode (oldOption );
// Alert (xxx. innerHTML );
}

Function show (s_id, index)
{
Var xxx = document. getElementById (s_id );
Var oldOption = xxx. children (index );
If (oldOption. tagName = 'div ')
{
Var oldStr = oldOption. innerText;
Var newOption = document. createElement ('<option' + oldOption. outerHTML. match (/(<\ w *) ([^>] *) (>)/) [2] + '> ');
NewOption. innerText = oldStr;
NewOption. swapNode (oldOption );
}
// Alert (xxx. innerHTML );
}



Function onchange1 ()
{
Var s_index = document. getElementById ("Ddl_question1"). options [document. getElementById ("Ddl_question1"). selectedIndex]. value;
S_index = parseInt (s_index );
If (s_index = 0)
{
Show ('ddl _ question2 ', Arrchange1 [0]);
Show ('ddl _ question3', Arrchange1 [0]);
Arrchange1.pop ();
}
Else
{
Arrchange1.push (s_index );
If (Arrchange1.length> 0)
{
Show ('ddl _ question2 ', Arrchange1 [0]);
}
If (Arrchange1.length> 0)
{
Show ('ddl _ question3', Arrchange1 [0]);
}
Hide ('ddl _ question2 ', s_index );
Hide ('ddl _ question3 ', s_index );
}
}
Function onchange2 ()
{
Var s_index = document. getElementById ("Ddl_question2"). options [document. getElementById ("Ddl_question2"). selectedIndex]. value;
S_index = parseInt (s_index );
If (s_index = 0)
{
Show ('ddl _ question1 ', Arrchange1 [0]);
Show ('ddl _ question3', Arrchange3 [0]);
Arrchange2.pop ();
}
Else
{
Arrchange2.push (s_index );
If (Arrchange2.length> 0)
{
Show ('ddl _ question1 ', Arrchange2 [0]);
}
If (Arrchange2.length> 0)
{
Show ('ddl _ question3', Arrchange2 [0]);
}
Hide ('ddl _ question1 ', s_index );
Hide ('ddl _ question3 ', s_index );
}
}
Function onchange3 ()
{
Var s_index = document. getElementById ("Ddl_question3"). options [document. getElementById ("Ddl_question3"). selectedIndex]. value;
S_index = parseInt (s_index );
If (s_index = 0)
{
Show ('ddl _ question1 ', Arrchange3 [0]);
Show ('ddl _ question2 ', Arrchange3 [0]);
Arrchange3.pop ();
}
Else
{
Arrchange3.push (s_index );
If (Arrchange1.length> 0)
{
Show ('ddl _ question1 ', Arrchange3 [0]);
}
If (Arrchange2.length> 0)
{
Show ('ddl _ question2 ', Arrchange3 [0]);
}
Hide ('ddl _ question1 ', s_index );
Hide ('ddl _ question2 ', s_index );
}
}

Function a () {alert ("fuck ");}
</Script>

<Select name = "Ddl_question1" id = "Ddl_question1" onchange = "onchange1 ()">
<Option value = "0"> select Confidential Information </option>
<Option value = "1"> What is your mother's name? </Option>
<Option value = "2"> what is your father's name? </Option>
<Option value = "3"> what is the name of your spouse? </Option>
<Option value = "4"> where is your birthplace? </Option>
<Option value = "5"> what is the name of your high school class teacher? </Option>
<Option value = "6"> what is the name of your junior high school class teacher? </Option>
<Option value = "7"> what is the name of your primary school class teacher? </Option>
<Option value = "8"> What is your primary school name? </Option>
<Option value = "9"> what is your student ID (or employee ID? </Option>
<Option value = "10"> what is your father's birthday? </Option>
<Option value = "11"> What is your mother's birthday? </Option>
<Option value = "12"> what is your spouse's birthday? </Option>

</Select>
<Select name = "Ddl_question2" id = "Ddl_question2" onchange = "onchange2 ()">
<Option value = "0"> select Confidential Information </option>
<Option value = "1"> What is your mother's name? </Option>
<Option value = "2"> what is your father's name? </Option>
<Option value = "3"> what is the name of your spouse? </Option>
<Option value = "4"> where is your birthplace? </Option>
<Option value = "5"> what is the name of your high school class teacher? </Option>
<Option value = "6"> what is the name of your junior high school class teacher? </Option>
<Option value = "7"> what is the name of your primary school class teacher? </Option>
<Option value = "8"> What is your primary school name? </Option>
<Option value = "9"> what is your student ID (or employee ID? </Option>
<Option value = "10"> what is your father's birthday? </Option>
<Option value = "11"> What is your mother's birthday? </Option>
<Option value = "12"> what is your spouse's birthday? </Option>

</Select>
<Select name = "Ddl_question3" id = "Ddl_question3" onchange = "onchange3 ()">
<Option value = "0"> select Confidential Information </option>
<Option value = "1"> What is your mother's name? </Option>
<Option value = "2"> what is your father's name? </Option>
<Option value = "3"> what is the name of your spouse? </Option>
<Option value = "4"> where is your birthplace? </Option>
<Option value = "5"> what is the name of your high school class teacher? </Option>
<Option value = "6"> what is the name of your junior high school class teacher? </Option>
<Option value = "7"> what is the name of your primary school class teacher? </Option>
<Option value = "8"> What is your primary school name? </Option>
<Option value = "9"> what is your student ID (or employee ID? </Option>
<Option value = "10"> what is your father's birthday? </Option>
<Option value = "11"> What is your mother's birthday? </Option>
<Option value = "12"> what is your spouse's birthday? </Option>

</Select>

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.