how to get the value of the dropdownlist selected
-
iam adding items to the dropdownlist using javascript function while loading the page.using the webservice.now when click on save button how can i get the value selected in the dropdownlist in the code behind,my problem is that the value selected in the dropdownlist is getting null when i accessing through code behind
-
iam adding items to the dropdownlist using javascript function while loading the page.using the webservice.now when click on save button how can i get the value selected in the dropdownlist in the code behind,my problem is that the value selected in the dropdownlist is getting null when i accessing through code behind
Show the code for both JavaScript and Codebehind ( just adding item in Dropdown and Retreving from it ).
cheers, Abhijit CodeProject MVP Web Site:abhijitjana.net My Latest Article : IIS Remote Debugging
-
Show the code for both JavaScript and Codebehind ( just adding item in Dropdown and Retreving from it ).
cheers, Abhijit CodeProject MVP Web Site:abhijitjana.net My Latest Article : IIS Remote Debugging
in javascript ============= <script type="text/javascript" language ="javascript" > function AddItem() { var opt = document.createElement("option"); document.getElementById("DropDownList1").options.add(opt); opt.text="One"; opt.value="One" var opt = document.createElement("option"); document.getElementById("DropDownList1").options.add(opt); opt.text="Two"; opt.value="Two" var opt = document.createElement("option"); document.getElementById("DropDownList1").options.add(opt); opt.text="Three"; opt.value="Three"; return false; } function GetDropDownValue() { alert("h") var ddlValue; var objControl = document.getElementById('<%=DropDownList1.ClientID %>'); alert(objControl.selectedIndex) ddlValue=objControl.options[o bjControl.selectedIndex].value; document.getElementById('hfldResult').value = ddlValue; } </script> in code behind Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click Dim tJavaScript As String = "" tJavaScript = "<script language='javascript'>GetDropDownValue();</script>" Page.ClientScript.RegisterStartupScript(Me.GetType, "abc", tJavaScript) End Sub
-
in javascript ============= <script type="text/javascript" language ="javascript" > function AddItem() { var opt = document.createElement("option"); document.getElementById("DropDownList1").options.add(opt); opt.text="One"; opt.value="One" var opt = document.createElement("option"); document.getElementById("DropDownList1").options.add(opt); opt.text="Two"; opt.value="Two" var opt = document.createElement("option"); document.getElementById("DropDownList1").options.add(opt); opt.text="Three"; opt.value="Three"; return false; } function GetDropDownValue() { alert("h") var ddlValue; var objControl = document.getElementById('<%=DropDownList1.ClientID %>'); alert(objControl.selectedIndex) ddlValue=objControl.options[o bjControl.selectedIndex].value; document.getElementById('hfldResult').value = ddlValue; } </script> in code behind Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click Dim tJavaScript As String = "" tJavaScript = "<script language='javascript'>GetDropDownValue();</script>" Page.ClientScript.RegisterStartupScript(Me.GetType, "abc", tJavaScript) End Sub
lakshmichawala wrote:
document.getElementById('hfldResult').value = ddlValue;
So, are you accessing this control, or the drop list in your code behind ? You have not posted that code, that I can see.
Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
-
lakshmichawala wrote:
document.getElementById('hfldResult').value = ddlValue;
So, are you accessing this control, or the drop list in your code behind ? You have not posted that code, that I can see.
Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
ya in hidden field iam giving the ddl selected value but iam getting null while accessing the value
-
in javascript ============= <script type="text/javascript" language ="javascript" > function AddItem() { var opt = document.createElement("option"); document.getElementById("DropDownList1").options.add(opt); opt.text="One"; opt.value="One" var opt = document.createElement("option"); document.getElementById("DropDownList1").options.add(opt); opt.text="Two"; opt.value="Two" var opt = document.createElement("option"); document.getElementById("DropDownList1").options.add(opt); opt.text="Three"; opt.value="Three"; return false; } function GetDropDownValue() { alert("h") var ddlValue; var objControl = document.getElementById('<%=DropDownList1.ClientID %>'); alert(objControl.selectedIndex) ddlValue=objControl.options[o bjControl.selectedIndex].value; document.getElementById('hfldResult').value = ddlValue; } </script> in code behind Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click Dim tJavaScript As String = "" tJavaScript = "<script language='javascript'>GetDropDownValue();</script>" Page.ClientScript.RegisterStartupScript(Me.GetType, "abc", tJavaScript) End Sub
I really don't understand what you are doing.:confused:
lakshmichawala wrote:
var opt = document.createElement("option"); document.getElementById("DropDownList1").options.add(opt);
Where you actual create the DrodownList list? Sometimes you are get taking
document.getElementById("DropDownList1")
and some time
document.getElementById('<%=DropDownList1.ClientID %>');
Please be specific what is your actual requirement is. As per my understanding You have a Dropdownlist ( Server Side Control ) you add value in the list from JavaScript. Now you want to access the value from Code behind itself. Correct me if I am wrong.
cheers, Abhijit CodeProject MVP Web Site:abhijitjana.net My Latest Article : IIS Remote Debugging
-
in javascript ============= <script type="text/javascript" language ="javascript" > function AddItem() { var opt = document.createElement("option"); document.getElementById("DropDownList1").options.add(opt); opt.text="One"; opt.value="One" var opt = document.createElement("option"); document.getElementById("DropDownList1").options.add(opt); opt.text="Two"; opt.value="Two" var opt = document.createElement("option"); document.getElementById("DropDownList1").options.add(opt); opt.text="Three"; opt.value="Three"; return false; } function GetDropDownValue() { alert("h") var ddlValue; var objControl = document.getElementById('<%=DropDownList1.ClientID %>'); alert(objControl.selectedIndex) ddlValue=objControl.options[o bjControl.selectedIndex].value; document.getElementById('hfldResult').value = ddlValue; } </script> in code behind Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click Dim tJavaScript As String = "" tJavaScript = "<script language='javascript'>GetDropDownValue();</script>" Page.ClientScript.RegisterStartupScript(Me.GetType, "abc", tJavaScript) End Sub
lakshmichawala wrote:
document.getElementById("DropDownList1").options.add(opt);
access your dropdown in javascript document.getElementById("<%=DropDownList1.ClientID %>").options.add(opt); I dont think that your value is getting updated in dropdown
Cheers!! Brij
-
lakshmichawala wrote:
document.getElementById("DropDownList1").options.add(opt);
access your dropdown in javascript document.getElementById("<%=DropDownList1.ClientID %>").options.add(opt); I dont think that your value is getting updated in dropdown
Cheers!! Brij
tq i hv solved my problem using request.form in my code behind eg: request.form("dropdownlist1")
-
tq i hv solved my problem using request.form in my code behind eg: request.form("dropdownlist1")
-
ya in hidden field iam giving the ddl selected value but iam getting null while accessing the value
Are you trying to make it impossible for people to help you ? How about posting the code you use to access the value, the script for the control, etc. Why are you not using the client ID from the server to access the hidden field, but you do for the drop down list ? Have you inserts js code to make sure the right control is being found and it's value set ?
Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.