Use JavaScript to move the list in two listboxes

Source: Internet
Author: User
Use JavaScript to move the list in two listboxes

Note:
1. ListBox is a server control, and list can be initialized on the server.
2. The button can be a server or a client control:
If it is a server-side control, you need to add an event to it during page initialization as follows:

Btn_updaddrel.attributes.add ("onclick", "javascript: add ();");
If it is a client control, specify event processing when declaring the control:

<Input type = "button" value = "add" onclick = "add ()">

3. event handling

<Script language = "JavaScript">
Function add ()
{
VaR objres = Document. getelementbyid ("lb_updrestitems ");
VaR objsel = Document. getelementbyid ("lb_updselitems ");

VaR customoptions;
For (VAR I = objres. Options. Length-1; I> = 0; I --)
{
If (objres. Options. Selected)
{
Customoptions = Document. createelement ("option ");
Customoptions. Text = objres. Options. text;
Customoptions. value = objres. Options. value;
Objsel. Add (customoptions, 0 );
Objres. Remove (I );
}
}
Return false;
}
</SCRIPT>

 

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.