How to add option [zz] To opener forms through opened forms in Javascript

Source: Internet
Author: User
Http://www.cnblogs.com/tonyqus/archive/2005/05/18/158357.html
If we want to dynamically add an option using JavaScript in a common form, we will write: document. form1.list1. options [0] = New Option ("A1", "A1 ");

Suppose there is a form named form1, and one list1 is the list.

If the above Code is called in the current window, a text = "A1", value = "A1" will be added, equivalent to the Code <option value = "A1"> A1 </option>

Note: The opener mentioned in this Article refers to a window for opening another window, and another window is called an opened window in this article.

Since this method is feasible, can we control the opener form in the opened form and create an option in the opener form? The theoretical code is as follows: zookeeper opener.doc ument. All. list1.options [0] = New Option ("AA", "AA ");

Assume that the opener form contains a list with name = list1.

However, if the above code is executed, it will not produce any effect. If we analyze the cause, we will find that the object generated by new option () is in the opened form, rather than in the opener form, which is specified in javascript: only allow the form to access its own variable object. Therefore, the correct method should be: var newopt?##opener.doc ument. createelement ("option ");
Newopt. Text = "AA ";
Newopt. value = "AA ";
Zookeeper opener.doc ument. All. list1.options. Add (newopt );

In this way, you can create an option in the opener form.

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.