Implementation Method to keep the value unchanged after two-level linkage select refresh

Source: Internet
Author: User

Background

Or the relationship between the school and the major. I need to keep the value before submission in the select statement on the page after clicking the submit button.

There are several methods on the internet, either to return the page through parameters included in the url jump, or to save the select value in the cookie when submitting, and then enter the value in the cookie back to the select.

The select value remains unchanged after the refresh is implemented according to the method saved in the cookie, and an onchange event is set for the select statement.
Copy codeThe Code is as follows:
<Script type = "text/javascript">
Window. onload = function (){
Var cooki = document. cookie;
If (cooki! = ""){
Cooki = "{\" "+ cooki + "\"}";
Cooki = cooki. replace (/\ s */g ,""). replace (/=/g ,'":"'). replace (// g ,'","');
Var json = eval ("(" + cooki + ")"); // convert coolies into a json object
Document. getElementById ("selectID"). options [json. selIndex]. selected = true; // keep the original options
}
Else
Save ();
}
Function change ()
{
SelectIndex = document. getElementById ("selectID"). selectedIndex;
Document. cookie = 'selindex = '+ selectIndex; // save it in the cookie with the key name selIndex
}
</Script>

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.