0

I have some markup:

<select name="serviceID[1]" id="serviceID[1]" class="computeThisService">
<option value="" selected="selected">No Selection</option>
<option value="4">TJ5</option>
<option value="1">TJ2</option>
<option value="5">TJ1</option>
<option value="2">TJ3</option>
</select>

I am trying to get the selected value and this does not work:

  var triggerID = event.target.id; // get the id that triggered the event
  var nStart = triggerID.indexOf('[') + 1;
  var nEnd = triggerID.indexOf(']');
  j = triggerID.substring(nStart, nEnd); // get the index of the id that triggered the event

  var el = $('select option:selected', this);
  alert(el.text());

2 Answers 2

2

You can use selectedIndex:

$("#serviceID\\[1\\]")[0].selectedIndex

Fiddle Demo

Sign up to request clarification or add additional context in comments.

1 Comment

I tried that too earlier and it did not work @Felix. But I'll try again
1

For jQuery all you need is this -

$('select option:selected').text();

So in your case it can be

$('#serviceID\\[1\\] option:selected').text();

http://jsfiddle.net/jayblanchard/StMd2/

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.