Create a cascading drop-down list box from a JavaScript script __java

Source: Internet
Author: User

This module uses JavaScript technology to determine whether the search condition is empty and to change the data in the corresponding list based on the data selected by the user. When the user selects a search condition in the first list, the data in the second list changes and corresponds to the data in the first list, with the following key code:

Code location: Supporting Resources \mr\01\select.php

01  <script>  02  function fetch () {                //determines whether the search keyword is empty   03       if (form1.key.value== "") {  04          alert (" Please enter a search keyword. ");   05          form1.value.select ();   06          return false;   07      }   08           return true;   09&NBSP;&NBSP}   10  </script>  11  <script language= " JavaScript ">  12  function press (opt) {             //defines the press () method, controls the Select2 display value   13  //opt for the Drop-down list box to indicate the number of existing options   14      &nbsP;form1.select2.options[opt]=new option (ok= (form1.select2.options[opt))?   15       form1.select2.options[opt].innertext+string.fromcharcode (Event.keycode):   16       string.fromcharcode (Event.keycode), OK)   17       form1.select2.selectedindex=opt;   18&NBSP;&NBSP}   19  </script>  20  <script language= " JavaScript ">  21  function up (opt) {            //defines the up () method to control Select2 value   22&NBSP;&NBSP;//OPT indicates the number of existing options   23       if (Form1.select2.options[opt]) {  24           if (event.keycode==8) {  25               var str=form1.select2.options[opt].innerText;   26&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&Nbsp;        var len=str.length;   27               Form1.select2.options[opt].innertext=str.substring (0,len-1);   28              if ( form1.select2.options[opt].innertext== " ") Select2.remove (2);   29          }   30           if (event.keycode==32) {  31               form1.select2.options[opt].innertext+= " ";   32          }   33       }   34  }   35  </script> 

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.