i need to fetch a value of a <p:selectOneMenu>
in javascript but the result that i get is null. I am able to call the function but when i am trying to access the value of the <p:selectOneMenu>
. i get null in alert box.
Please find the below code.
<p:outputLabel for="year" value="Year: " />
<p:selectOneMenu id="year" style="width:150px " value="#{someBean.year}">
<f:selectItem itemLabel="All" itemValue="All"/>
<f:selectItem itemLabel="2014" itemValue="2014"/>
<f:selectItem itemLabel="2013" itemValue="2013"/>
<f:selectItem itemLabel="2012" itemValue="2012"/>
<f:selectItem itemLabel="2011" itemValue="2011"/>
<f:selectItem itemLabel="2010" itemValue="2010"/>
<f:selectItem itemLabel="2009" itemValue="2009"/>
</p:selectOneMenu>
Javascript function:
function validateYearMonth()
{
var yearValue1=document.getElementById('Form:year_input');
var yearValue2=document.getElementById('Form:year');
alert(yearValue1);
alert(yearValue2);
}
Call to function:
<p:commandButton id="Submit" action="#{someBean.functionName}"
onclick="validateYearMonth()" value="Submit" ajax="false" style="float:right;">
</p:commandButton>
I dont understand whats wrong. while i am able fetch the element if i am doing
var yearValue1=document.getElementById('Form:year_input');
but i am not able to fetch the value. Any help much appreciated.