Implementation of Automatic drop-down boxes in ASP. NET (C #)

Source: Internet
Author: User
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" > <Title> text box automatically prompted by Ajax </title> <style> <!-- body{      font-family:Arial, Helvetica, sans-serif;      font-size:12px; padding:0px; margin:5px; } form{padding:0px; margin:0px;} input{      /* Style of the user input box */      font-family:Arial, Helvetica, sans-serif;      font-size:12px; border:1px solid #000000;      width:200px; padding:1px; margin:0px; } #popup{      /* Style of the DIV block in the prompt box */      position:absolute; width:202px;      color:#004a7e; font-size:12px;      font-family:Arial, Helvetica, sans-serif;      left:41px; top:25px; } #popup.show{      /* Display the border of the prompt box */      border:1px solid #004a7e; } #popup.hide{      /* Hide the border of the prompt box */      border:none; } /* Style of the prompt box */ ul{      list-style:none;      margin:0px; padding:0px; } li.mouseOver{      background-color:#004a7e;      color:#FFFFFF; } li.mouseOut{      background-color:#FFFFFF;      color:#004a7e; } --> </style> <script language= "javascript" > var oInputField;    // Considering that many functions need to be used var oPopDiv;        // Therefore, global variables are used. var oColorsUl; var xmlHttp; function createXMLHttpRequest(){      if (window.ActiveXObject)          xmlHttp = new ActiveXObject( "Microsoft.XMLHTTP" );      else if (window.XMLHttpRequest)          xmlHttp = new XMLHttpRequest(); } function initVars(){      // Initialize the variable      oInputField = document.forms[ "myForm1" ].colors;      oPopDiv = document.getElementById( "popup" );      oColorsUl = document.getElementById( "colors_ul" ); } function clearColors(){      // Clear the prompt content      for (var i=oColorsUl.childNodes.length-1;i>=0;i--)          oColorsUl.removeChild(oColorsUl.childNodes[i]);      oPopDiv.className = "hide" ; } function setColors(the_colors){      // Display the prompt box. The input parameters are arrays composed of matched results.      clearColors();    // Clear the original prompt every time you enter a letter before continuing      oPopDiv.className = "show" ;      var oLi;      for (var i=0;i<the_colors.length;i++){          // Display the matching result to the user one by one          oLi = document.createElement( "li" );          oColorsUl.appendChild(oLi);          oLi.appendChild(document.createTextNode(the_colors[i]));             oLi.onmouseover = function(){              this .className = "mouseOver" ;    // Highlight when the mouse passes          }          oLi.onmouseout = function(){              this .className = "mouseOut" ;    // Restore to original state upon departure          }          oLi.onclick = function(){              // When you click a matching item, set the input box to the value of the item.              oInputField.value = this .firstChild.nodeValue;              clearColors();    // Clear the prompt box at the same time          }      } } function findColors(){      initVars();        // Initialize the variable      if (oInputField.value.length > 0){          createXMLHttpRequest();        // Send user input to the server          var sUrl = "9-10.aspx?sColor=" + oInputField.value + "&timestamp=" + new Date().getTime();          xmlHttp.open( "GET" ,sUrl, true );          xmlHttp.onreadystatechange = function(){              if (xmlHttp.readyState == 4 && xmlHttp.status == 200){                  var aResult = new Array();                  if (xmlHttp.responseText.length){                      aResult = xmlHttp.responseText.split( "," );                      setColors(aResult);    // Display Server results                  }                  else                      clearColors();              }          }          xmlHttp.send( null );      }              else          clearColors();    // Clear the prompt box when there is no input (for example, press the Del key) } </script> <body> <form method= "post" name= "myForm1" > Color: <input type= "text" name= "colors" id= "colors" onkeyup= "findColors();" /> </form> <div id= "popup" >      <ul id= "colors_ul" ></ul> </div> </body>

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.