1

My asp controls:

<asp:TextBox ID="txtCustomer" runat="server" width="54%" onchange="return info();">      </asp:TextBox>
 <asp:HiddenField ID="hdn" runat="server" />
<asp:DropDownList ID="ddlrNo" runat="server">
 </asp:DropDownList>

My javascript function:

function info() {  

var ss = document.getElementById(hdn);   
 var ss1 = document.getElementById(ddlrNo);
  var str = ss.value    
 var arr = str.split("~");
 alert(arr[0])
 for (var i = 0; i < arr.length; i++) {

    ss1.selectedIndex = 0
    ss1.options[0].text = arr[0];
}
}

I have a textbox on which i have to call javascript function,to get value from hidden field to populate dropdown value based on that hidden filed.

but it is not working what is wrong with the code.

2 Answers 2

1

there are some things incorrect in the code first document.getElementById(hdn); should be used in single or double quotes e.g.

document.getElementById("hdn");

same is the case with next line as well then ss1.options[0].text this is incorrect as well .value is more appropriate when accessing drop down list in javascript

Sign up to request clarification or add additional context in comments.

3 Comments

If i am trying to get the value through "" then showing null in alert alert(document.getElementById("hdn"))
thats because arr[0] has nothing to show, u need more to understand about how do to do things in javascript, perhaps u would better use .getElementById("txtCustomer") in place of hdn
For other controls alert message showing OBJECTHTMLINPUTELEMENT. Nd arr[0] is written later in the js code,from the begining i am giving the alert
0

Try this

<asp:TextBox ID="txtCustomer" runat="server" width="54%" onblur="javascript:info()"/>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.