2012-03-02 31 views
0

我有一个asp.net下拉列表框,我想基于通过JavaScript的文本框的值填充它。该值将传递给我创建的存储过程,结果将填充到下拉列表中。填入从JavaScript中的文本框下拉菜单

我做了我的研究,但我似乎无法找到正确的解决方案。

需要帮助。

[UPDATE] 这里的源代码,我最初所做的: HTML:

<asp:DropDownList runat="server" id="cboPriceID" AutoPostBack="true" onblur="LoadPrice()"/> 

我具有被从存储过程中检索到的数据表。我目前拥有的是一个填充文本框的JavaScript代码。

 function LoadPart_CallBack(response) { 
     //if the server-side code threw an exception 
     debugger; 
     if (response.error != null) { 
      //we should probably do better than this 
      alert(response.error); 

      return; 
     } 

     var ResponseValue = response.value; 


     var al = ResponseValue.split(":"); 
     var errormsg = al[0]; 
     var partname = al[1]; 


     if (errormsg == "") { 

      document.getElementById("<%=txtPartName.ClientID%>").value = partname; 
      } 
     } 

需要关于如何填充它的帮助。

+0

看一看这个问题** HTTP://stackoverflow.com/questions/5511273/populate-drop-down-list-using-jquery-from-textbox** – 2012-03-02 09:08:52

+0

张贴一些HTML这里.. – 2012-03-02 09:11:26

+0

@Amit:实际上并不多加。我只在那里有我的下拉控制。我仍在考虑如何从文本框中进行级联。 – Musikero31 2012-03-02 09:41:27

回答

0
<html> 
<body> 
<input type="text" id="data" name="data"/> 
<input type="button" value="Add" onclick="addData()"><br/> 
<select id="choice"> 
</select> 
<script type="text/javascript"> 
function addData() 
{ 
    var txt=document.getElementById("data").value; 
    if(txt!="") 
    { 
    var newcontent = document.createElement('option'); 
    newcontent.innerHTML = txt; 
    document.getElementById("choice").appendChild(newcontent); 
    document.getElementById("data").value=""; 
    } 
} 
</script> 

</body> 
</html>