JS functions for adjusting the select position

Source: Internet
Author: User

// Sort: Move Up
Function up ()
...{
VaR sel = Document. getelementbyid ("selectcheck"); // obtain select
VaR nindex = SEL. selectedindex; // index of the select item to be operated
VaR nlen = SEL. length; // total number of select projects
If (nlen <1) | (nindex = 0) return;
If (nindex <0)
...{
Alert ("select a selected button to move! ");
Return;
}
VaR svalue = SEL. Options [nindex]. value;
VaR shtml = SEL. Options [nindex]. innerhtml;
Sel. Options [nindex]. value = SEL. Options [nIndex-1]. value;
Sel. Options [nindex]. innerhtml = SEL. Options [nIndex-1]. innerhtml;
Sel. Options [nIndex-1]. value = svalue;
Sel. Options [nIndex-1]. innerhtml = shtml;
Sel. selectedindex = nIndex-1;
}
// Sort: Move down
Function down ()
...{
VaR sel = Document. getelementbyid ("selectcheck ");
VaR nindex = SEL. selectedindex;
VaR nlen = SEL. length;
If (nlen <1) | (nindex = nLen-1) return;
If (nindex <0)
...{
Alert ("select a selected button to move! ");
Return;
}
VaR svalue = SEL. Options [nindex]. value;
VaR shtml = SEL. Options [nindex]. innerhtml;
Sel. Options [nindex]. value = SEL. Options [nindex + 1]. value;
Sel. Options [nindex]. innerhtml = SEL. Options [nindex + 1]. innerhtml;
Sel. Options [nindex + 1]. value = svalue;
Sel. Options [nindex + 1]. innerhtml = shtml;
Sel. selectedindex = nindex + 1;
}
// Move to the top
Function upfirst ()
...{
VaR sel = Document. getelementbyid ("selectcheck ");
VaR nindex = SEL. selectedindex;
VaR nlen = SEL. Options. length;
If (nlen <1) | (nindex = 0) return;

If (nindex <0)
...{
Alert ("select a selected button to move! ");
Return;
}
VaR tempvalue = Document. getelementbyid ("tempvalue"); // used to temporarily store the option value
Tempvalue. value = "";
For (var k = 0; k <nindex; k ++)
...{
Tempvalue. Value + = SEL. Options [K]. Value + ";";
}
VaR arrvalue = tempvalue. value. Split (';');
VaR svalue = SEL. Options [nindex]. value;
VaR shtml = SEL. Options [nindex]. innerhtml;
Sel. Options [0]. value = svalue;
Sel. Options [0]. innerhtml = shtml;

For (VAR j = 1; j <= nindex; j ++)
...{
Sel. Options [J]. value = arrvalue [J-1];
Sel. Options [J]. innerhtml = arrvalue [J-1];
}
Sel. selectedindex = 0;
}
// Move to the end
Function downlast ()
...{
VaR sel = Document. getelementbyid ("selectcheck ");
VaR nindex = SEL. selectedindex;
VaR nlen = SEL. Options. length;
If (nlen <1) | (nindex = nlen) return;

If (nindex <0)
...{
Alert ("select a selected button to move! ");
Return;
}
VaR tempvalue = Document. getelementbyid ("tempvalue"); // used to temporarily store the option value
Tempvalue. value = "";
For (var k = nindex + 1; k <nlen; k ++)
...{
Tempvalue. Value + = SEL. Options [K]. Text + ";";
}
VaR arrvalue = tempvalue. value. Split (';');
VaR svalue = SEL. Options [nindex]. value;
VaR shtml = SEL. Options [nindex]. innerhtml;

For (var j = nindex; j <nlen; j ++)
...{
Sel. Options [J]. value = arrvalue [J-nindex];
Sel. Options [J]. innerhtml = arrvalue [J-nindex];
}

Sel. Options [nLen-1]. value = svalue;
Sel. Options [nLen-1]. innerhtml = shtml;
Sel. selectedindex = nLen-1;
}

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.