if the month was less than today's month then I should show an error message through javascript in visualforce page…….I have tried but unable to…here is my code
/*javascript*/
<script type="text/javascript">
function validmonth()
{
if(exm < Month(today()))
{
condition=1;
alert("Invalid month");
jQuery(".exm").focus();
return false;
}
}
</script>
/* page */
<apex:selectlist value="{!Item.ExpirationMonth}" size="1" styleclass="exm" >
<apex:selectOptions value="{!item.ExpireMonth}"/>
</apex:selectlist>
/* in constructor */
string dd=datetime.now().format('MM/dd/yyyy');
string mon=dd.substring(0,2);
string year=dd.substring(7,10);
item.ExpirationMonth=mon;
This function validmonth() Ill be calling in Command button…..
Best Answer
You need to use the LIVE Jquery Event to bind to the Change event on the Select List. Here is an example I mocked up. I've used Javascript to get the month (0-11, hence increment by 1)
Controller :