views:

179

answers:

1

Can I get html select option label based on option value

<select id="xx">
  <option value="i_Have_value">I Need This Label</option>
  <option value="i_Have_value2">I Need This Label2</option>
</select>

By using jsf selectOneMenu and rich:comboBox in single form, i landed up in this kind of requirement.

A: 

By using jsf selectOneMenu and rich:comboBox in single form

JSF is a server side component based MVC framework which generates HTML. JavaScript is a client side scripting language which only has access to the HTML DOM tree.

Thus, when writing JavaScript code for a JSF webapplication, you should not look at the JSF source code, but at its generated HTML output (open page in browser, rightclick and view source).

You'll under each notice that the generated HTML element ID's are actually prepended with the HTML element ID's of the JSF UINamingContainer components (e.g. UIForm, UIData). Thus, the actual HTML element ID of your dropdown element may be rather "formId:dropdownId". You need to use exactly that ID in JavaScript.

In the future, when posting this kind of questions in StackOverflow, please talk in JSF context, not in HTML context, certainly as long as you don't understand how JSF works under the hood. This way you'll also have more chance that others will post more JSF-suited answers and suggestions so that you don't need to "hack" it low-level with JavaScript. There's namely often no need to do so.

Good luck.

BalusC