JavaScript calls XML make a pull down box

Source: Internet
Author: User
Tags add array html page

There are two ways to move a drop-down box in a traditional HTML page:
1 directly hardcode the contents of the dropdown box into JavaScript in HTML, invoking JavaScript function loops to write to the Drop-down box. This method does not apply to situations where the content of the dropdown box changes frequently. Because the data source and JavaScript program are written dead on the same page.



List





Onchange= "Changelocation (Document.myform.biglocation.options[document.myform.biglocation.selectedindex].value) "> Jiangxi
== All areas ==




2 JavaScript reads the database directly, takes the records in the database to the JavaScript, and then, like the first method, invokes the JavaScript function loop to write to the Drop-down box. This method separates the data source from JavaScript, but exposes the connection to the database and, from a security standpoint, has little practical value.


My approach is to put the data in the Drop-down box in an XML file, read the XML file with JavaScript, and get the contents of the Drop-down box.

The HTML file is as follows:



call XML data in HTML



Type

Sub-class


Account.xml is as follows:




not available


dangdang1
dangdang2
dangdang3
dangdang4
dangdang5
dangdang6


zhuce_user1
zhuce_user2


tongxun

This method separates the data source from the JavaScript program and is suitable for frequently changing data sources. Xmldoc.load can call URL parameters directly, read remote XML, and achieve loose coupling. The above application is passed in the IE6.0. The disadvantage is that you need to remove the dropdown box list content
Repeat the delete operation, otherwise there will be a noticeable bug. I hope that some readers can correct me.



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.