Batman
Batman

Reputation: 6353

Trying to capture value of selected option

I have a select box and I'm trying to get value of the selected option. I get error Property 'value' of object # is not a function

HTML:

    <select id="my_SiteUsers" style="width:350px;" onchange="RefreshGroupLists()">
<option  
     value="i:0#.w|itun\akondruss_fg">Alex</option>
<option value="i:0#.w|itun\allepage_fg">Alex</option>
</select>

enter image description here

JS:

  var e = document.getElementById("my_SiteUsers");
  var user = e.value();
  alert(user);

Upvotes: 0

Views: 1857

Answers (2)

HC_
HC_

Reputation: 1050

Try using jquery's .val(), like many jq functions it will be (possibly) much easier than through js.

// Get the value from a dropdown select
$( "select.foo option:selected").val();

documentation: http://api.jquery.com/val/

edit-- looks like the above solution solved it more easily :)

Upvotes: 0

adeneo
adeneo

Reputation: 318192

value is not a function, it's a property of the DOM node :

var e = document.getElementById("my_SiteUsers");
var user = e.value;
alert(user);

or with jQuery:

var user = $('#my_SiteUsers').val();

Upvotes: 2

Related Questions