Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
135
rated 0 times [  136] [ 1]  / answers: 1 / hits: 15826  / 13 Years ago, fri, november 11, 2011, 12:00:00

Hi am trying to get the value of p:selectOneMenu from jquery , but i dint got as yet. am using JSF and primefaces as my UI component.



    <p:selectOneMenu style=width:150px id=skill
value=#{loginBean.skill} required=true immediate=true
requiredMessage=Select your skill label=skill styleClass=someClassName>
<f:selectItem itemLabel=Select itemValue=></f:selectItem>
<f:selectItem itemLabel=Other itemValue=Other></f:selectItem>
<f:selectItems value=#{loginBean.skillList} var=item
itemLabel=#{item} itemValue=#{item}></f:selectItems>
</p:selectOneMenu>


In Html



<select id=skill_input name=skill_input>
<option value=>Select</option>
<option value=Other>Other</option>
<option value=Tailoring>Tailoring</option>
<option value=Swimming>Swimming</option>
<option value=Roaming>Roaming</option>
</select>


thats my select one menu, my js is..



  var $element = $('.someClassName');

alert($element);


in the alert box i got as, [object Object], but not the selected value.



then i tried this,



   var $element = $('.someClassName').val();

alert($element);


but now i got an empty alert box.



then i tried this



 var $element = $(select[name='skill_input']:selected).val();

alert($element);


my alert box says undefined



What else i should do to get the selected value in that alert box..??


More From » jquery

 Answers
3

Try this



var $element = $(select[name='skill_input'] option:selected).val();

alert($element);

[#89184] Thursday, November 10, 2011, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
neilshamarh

Total Points: 181
Total Questions: 94
Total Answers: 104

Location: Guadeloupe
Member since Sat, Aug 22, 2020
4 Years ago
;