sona
sona

Reputation: 1552

why textbox onchange event to call javascriptfunction not working?

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.

Upvotes: 1

Views: 693

Answers (2)

Shreyas Achar
Shreyas Achar

Reputation: 1435

Try this

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

Upvotes: 0

Usman Waheed
Usman Waheed

Reputation: 553

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

Upvotes: 1

Related Questions