Click here to Skip to main content
15,915,864 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am using Javascript to get those all values that user enters into the form. Also i have used database to fill the cascading dropdownlist(Country,States,City) and have thier values as well as text. My question is that when user clicks submit button i get the values of 'Country','States','City' like 10,101,1011 but i want text like USA,Carolina,C1 . My code is as follows:
C#
function callall()
      {
          var Name = document.getElementById("TextBox1").value;
          var DOB = document.getElementById("TextBox2").value;
          var Add = document.getElementById("TextBox3").value;
          var phn = document.getElementById("TextBox4").value;
          var Country = document.getElementById("DropDownList1").value;
          var State = document.getElementById("DropDownList2").value;
          var City = document.getElementById("DropDownList3").value;
          var msg = "Name: " + Name + ",DOB: " + DOB + ",Add: " + Add + ", phno: " + phn + ",Country: " + Country + ",State: " + State + ",City: " + City;
          return confirm(msg);
      }

please correct me. But i want to send values only in database not names to avoid redundancy.Thank u. In my dropdownlist text is visible not value.
Posted

Refer - Asp.net Get Dropdown Selected value and text in JavaScript[^].
JavaScript
<script type="text/javascript">
function GetCountryDetails() {
    // Get id of dropdownlist
    var parm = document.getElementById("ddlCountry");

    // Get Dropdownlist selected item text
    document.getElementById('lbltxt').innerHTML = parm.options[parm.selectedIndex].text;

    // Get Dropdownlist selected value item
    document.getElementById('lblid').innerHTML = parm.options[parm.selectedIndex].value;
}
</script>

You can also see the demo there.
 
Share this answer
 
Below is the syntax for the same.

var ddlCountry = document.getElementById("DropDownList1")
var Country =ddlCountry.options[ddlCountry.selectedIndex].text;
 
Share this answer
 
Comments
Rambo_Raja 28-Jun-13 2:41am    
Thnx..Solved;)
You can also accept my answer. Is there anything wrong in that? :)
Rambo_Raja 28-Jun-13 3:43am    
no dude..;) i have not done that intentionally
No problem R_sharma...
I know you have done that intentionally, I was just tying to confirm from you, if the solution I provided is correct or not. Sorry... Please don't take it otherwise.

And thanks a lot for accepting the answer. :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900