Add option dynamically for select

Source: Internet
Author: User

Question: today, we have made two multi-choice list boxes for a project to move each other. It is required to support browsers including FF, ie, and Safari (Apple.

Problem:

Symptom 1: When you use the objselect. appendchild (objopiton) method to add an option to the SELECT statement, the list items are displayed, but the items are blank.

Symptom 2: Use objselect. Add (objopiton) to add option, which is not supported in ff.

Key code (because it is a Japanese project, comments in Japanese can be ignored ):

Function moveselected (); vaR arrseltext = new array (); // when the configuration column is selected, the selection has been completed successfully. The selection has been completed successfully. var arrvaluetextrelation = new array (); var Index = 0; // The secondary primary Primary Secondary too many rows have been selected, and the value has been selected. Too many rows have been selected before each other has been set for (VAR I = 0; I <osourcesel. options. length; I ++) {If (osourcesel. options [I]. selected) {// specify arrselvalue [Index] = osourcesel. options [I]. value; arrseltext [Index] = osourcesel. options [I]. text; // value optional values selected when there are too many options when there are too many pending values under arrvaluetextrelation [arrselvalue [Index] = osourcesel. options [I]; index ++ ;}} // when there are too many threads, there will be too many threads, too many threads, and so on. when the primary Primary Secondary; I <arrseltext. length; I ++) {// append var ooption = document. createelement ("option"); otargetsel. appendchild (ooption) ooption. TEXT = arrseltext [I]; ooption. value = arrselvalue [I. removechild (arrvaluetextrelation [arrselvalue [I]);}
Observe the above Code lines 5-59
Symptom 1 code: ooption. Text = arrseltext [I]; ooption. value = arrselvalue [I]; otargetsel. appendchild (ooption );
The code for symptom 2 is: ooption. Text = arrseltext [I]; ooption. value = arrselvalue [I]; otargetsel. Add (ooption );
Conclusion:
Symptom 1: because IE and FF have different Dom operations, a blank list is displayed in IE, because a node or attribute value can be added to the node only after the node is obtained in IE.
FF does not have this constraint.
Symptom 2: The reason is simple. FF does not support adding subnodes by adding. IE does some special processing for ADD, so it can get the expected result.
In addition, the above three codes can run normally in safari. A good browser is as attractive as his appearance.

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.