Friday, May 17, 2024
 Popular · Latest · Hot · Upcoming
113
rated 0 times [  118] [ 5]  / answers: 1 / hits: 38108  / 11 Years ago, fri, july 5, 2013, 12:00:00

I have a select statement like this:



<select onchange=change_session() name=select_path id=select_path>
<option name=sserver_id id=select_path selected value={{ i.id }}>{{ default_server_id }}</option>
{% for i in all_server_id %}
<option name=server_id id=select_path value={{ i.id }}>{{ i.session_name }}</option>
{% endfor %}
</select>


The first option show the default_id on the top and the second options lists all the options. User can change the option and process accordingly which is send to server using AJAX. Now I want to find out which server_id has user selected using JavaScript like this:



var serverId=document.getElementById('server_id');


How can I get the selected option?


More From » html-select

 Answers
4

try this..



<select onchange=change_session() name=select_path id=select_path>
<option selected value={{ i.id }}>{{ default_server_id }}</option>
{% for i in all_server_id %}
<option value={{ i.id }}>{{ i.session_name }}</option>
{% endfor %}
</select>


code for javascript function



var serverId=document.getElementById('select_path').value;

[#77190] Wednesday, July 3, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
taylert

Total Points: 627
Total Questions: 91
Total Answers: 108

Location: Mayotte
Member since Mon, Sep 12, 2022
2 Years ago
taylert questions
;