Get value from javascript function into Dropdown and Display selected Value
-
Hello Friends, I've two dropdownlist(ddlCountry,ddlState). Onchange event of CountryDropdown(ddlCountry) StateNames are displayed into StateName dropdown using javascript. And it's working fine but prooblem is if i print the value of selected StateName on a button click at code-behind i got an error <b>Object reference set to an instance of an object</b>. So can anybody let me know what should i do know
-
Hello Friends, I've two dropdownlist(ddlCountry,ddlState). Onchange event of CountryDropdown(ddlCountry) StateNames are displayed into StateName dropdown using javascript. And it's working fine but prooblem is if i print the value of selected StateName on a button click at code-behind i got an error <b>Object reference set to an instance of an object</b>. So can anybody let me know what should i do know
your question is clear... Plzzzz send the code upto which level you have tried and the line where u r getting that error...
Padmanabhan My Articles: Articles[^] My latest Article: Word Automation[^]
-
your question is clear... Plzzzz send the code upto which level you have tried and the line where u r getting that error...
Padmanabhan My Articles: Articles[^] My latest Article: Word Automation[^]
This is my javascript function function myFunc() { if(document.getElementById("ddlCountry").value=="India") { //Remove Existing Values var e=document.getElementById("ddlState"); while(e.firstChild) { e.removeChild(e.firstChild); } var myArray=new Array(2); myArray[0]="Delhi"; myArray[1]="Mumbai"; for(var i=0;i<myArray.length;i++) { //Option(Text,Value) e.options[i]=new Option(myArray[i]); } } else if(document.getElementById("ddlCountry").value=="America") { //Remove Existing Values var e=document.getElementById("ddlState"); while(e.firstChild) { e.removeChild(e.firstChild); } var myArray=new Array(2); myArray[0]="Washington"; myArray[1]="LA"; for(var i=0;i<myArray.length;i++) { //Option(Text,Value) e.options[i]=new Option(myArray[i]); } } } This is my .aspx code <asp:DropDownList ID="ddlCountry" runat="server" onchange="myFunc(this)"> <asp:ListItem Text="Select Country" Value="Select Country"></asp:ListItem> <asp:ListItem Text="India" Value="India"></asp:ListItem> <asp:ListItem Text="America" Value="America"></asp:ListItem> </asp:DropDownList> <asp:DropDownList ID="ddlState" runat="server"> </asp:DropDownList> This is my Code-Behind(on button click event) code string name = ddlCountry.SelectedItem.Text+","+ddlState.SelectedItem.Text; Label1.Text = name.ToString(); And
-
This is my javascript function function myFunc() { if(document.getElementById("ddlCountry").value=="India") { //Remove Existing Values var e=document.getElementById("ddlState"); while(e.firstChild) { e.removeChild(e.firstChild); } var myArray=new Array(2); myArray[0]="Delhi"; myArray[1]="Mumbai"; for(var i=0;i<myArray.length;i++) { //Option(Text,Value) e.options[i]=new Option(myArray[i]); } } else if(document.getElementById("ddlCountry").value=="America") { //Remove Existing Values var e=document.getElementById("ddlState"); while(e.firstChild) { e.removeChild(e.firstChild); } var myArray=new Array(2); myArray[0]="Washington"; myArray[1]="LA"; for(var i=0;i<myArray.length;i++) { //Option(Text,Value) e.options[i]=new Option(myArray[i]); } } } This is my .aspx code <asp:DropDownList ID="ddlCountry" runat="server" onchange="myFunc(this)"> <asp:ListItem Text="Select Country" Value="Select Country"></asp:ListItem> <asp:ListItem Text="India" Value="India"></asp:ListItem> <asp:ListItem Text="America" Value="America"></asp:ListItem> </asp:DropDownList> <asp:DropDownList ID="ddlState" runat="server"> </asp:DropDownList> This is my Code-Behind(on button click event) code string name = ddlCountry.SelectedItem.Text+","+ddlState.SelectedItem.Text; Label1.Text = name.ToString(); And
i too got the same error from your code... The problem is due to postback. The ddlCountry value is maintained but ddlState value is not maintained. So, the error appears. Try to maintain the value for the ddlState too...
Padmanabhan My Articles: Articles[^] My latest Article: Word Automation[^]
-
i too got the same error from your code... The problem is due to postback. The ddlCountry value is maintained but ddlState value is not maintained. So, the error appears. Try to maintain the value for the ddlState too...
Padmanabhan My Articles: Articles[^] My latest Article: Word Automation[^]
Save the state of drop down list get value from request.form or query string do not fill all entry every time because if you did so every time new values is filled and state can not be maintained you can try one more option before submitting the form save the value into hidden variable by using java script and then get values from request object not from drop down because it lost their value when it fill again