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 usedvar oPopDiv; // Therefore, global variables are used.var oColorsUl; var xmlHttp; function createXMLHttpRequest(){ if(window.ActiveXObject) xmlHttp = newActiveXObject("Microsoft.XMLHTTP"); elseif(window.XMLHttpRequest) xmlHttp = newXMLHttpRequest(); } function initVars(){ // Initialize the variableoInputField = document.forms["myForm1"].colors; oPopDiv = document.getElementById("popup"); oColorsUl = document.getElementById("colors_ul"); } function clearColors(){ // Clear the prompt contentfor(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 continuingoPopDiv.className = "show"; var oLi; for(var i=0;i<the_colors.length;i++){ // Display the matching result to the user one by oneoLi = 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 variableif(oInputField.value.length > 0){ createXMLHttpRequest(); // Send user input to the servervar sUrl = "9-10.aspx?sColor="+ oInputField.value + "×tamp="+ newDate().getTime(); xmlHttp.open("GET",sUrl,true); xmlHttp.onreadystatechange = function(){ if(xmlHttp.readyState == 4 && xmlHttp.status == 200){ var aResult = newArray(); if(xmlHttp.responseText.length){ aResult = xmlHttp.responseText.split(","); setColors(aResult); // Display Server results} elseclearColors(); } } xmlHttp.send(null); } elseclearColors(); // 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>
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