Note that there are some explanatory texts on larger screens.

plurals
  1. POMultiple onClick events
    text
    copied!<p>I have a JSF page, a drop down where values are getting fetched from service. Default is "Select from Drop Down" and a datePicker and a submit button. </p> <p>I need to apply JS/AJAX validation here. </p> <p>If a user clicks on Submit button without chosing any value from the drop down and the date. It should first diplay a message,</p> <p><strong>1) If none chosen, first show a message - Please select a value from drop down.</strong> </p> <p><strong>2) if the value is selected from the drop down and date has not been selected It should display a message " select a date".</strong></p> <p><strong>3) if the date is selected and value is not selected from the drop down It should display a message " select a value from the drop down".</strong></p> <p>Both validation should be done on a single click on submit button.</p> <p>Currently it's just checking if date is not selected. onclick event code is mentioned below. </p> <p><strong>Drop Down</strong></p> <pre><code>&lt;h:selectOneMenu id="valueList" value="#bean.values"&gt; &lt;f:selectItem itemValue="Select Action" itemLabel="Select Action" /&gt; &lt;f:selectItems value="#{sampleService.sampleMethod}" var="SampleVar" itemValue="#{SampleVar}" itemLabel="#{SampleVar}"&gt; &lt;/f:selectItems&gt; &lt;/h:selectOneMenu&gt; </code></pre> <p><strong>Submit button</strong></p> <pre><code> &lt;ui:define name="actions"&gt; ----h:inputHidden id="getAllDates" value="#{serviceMethod.getAllDates}"----- &lt;h:commandButton styleClass="inputbutton" valuGenerate" id="export" action="#{generate.someReport}" onclick="saveDate(); /&gt; &lt;/ui:define&gt; </code></pre> <p>Passing all selected dates in hidden. <strong>OnClick event</strong> this js function is written in another file. </p> <blockquote> <p>onclick="saveDate();"</p> </blockquote> <pre><code>function saveDate() { var dates = $('#selectDates').datepick('getDate'); var datesValue = ''; if(dates==null || dates=="undefined"){ alert("Select Dates"); return false; } if(dates!=null){ // store in an array and return true } </code></pre> <p>Currently page is getting refreshed on every click on Submit button and alert message gets displayed only for date. </p> <p>Can anybody help me in applying ajax call on submit button and displaying validation messages?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload