Note that there are some explanatory texts on larger screens.

plurals
  1. POIssues with javascript not functioning and validating
    text
    copied!<p>I am trying to use javascript to validate some inputs, its nothing major, just thought it would be a nice finishing touch to my JSF project</p> <p>the backing bean already has validation not to accept any inputs less than 1, over 50, i jsut wanted to use JS as i have to use it and it would be nice to give the user this information</p> <p>i have :</p> <pre><code>&lt;h:body&gt; &lt;h:form id="myForm" onsubmit="return validateForm()"&gt; &lt;p&gt; Number of copies (Max of 50) : &lt;p:spinner id ="Copies" min="1" max="50" value="#{printerSettings.p}" size ="1"&gt; &lt;!-- allows the user a choice of up to 50, this is more than enough for any situation, if needed this can be removed or raised --&gt; &lt;p:ajax update="p"/&gt; &lt;/p:spinner&gt; &lt;div class="whiteSpace"/&gt; &lt;h:outputText value="Copies that will be printed: &amp;nbsp; #{printerSettings.p}" id="p"/&gt; &lt;/p&gt; ............. &lt;/div&gt; &lt;script type="text/javascript"&gt; function validateForm() { var x = document.forms["myForm"]["Copies"].value; if (x === 0 || x === "") { alert("Number of copies must be greater than 1 or less than 51"); return false; } } </code></pre> <p>but when ever the submit button is pressed </p> <pre><code>&lt;p:commandButton type="submit" action="#{email.mail(printerSettings.t, printerSettings.p, printerSettings.paperSize, printerSettings.duplex, printerSettings.orienation, printerSettings.printer)}" onclick="Thankyou()" value="Print" /&gt; </code></pre> <p>it does not validate or show up the javascript</p> <p>what the javascript is trying to do it just make sure the value in the spinner is between 1 and 50</p> <p>any ideas?</p> <p>EDIT</p> <p>i have added the code into this javascript which i know is getting called as the message displays and even with the code here it still does no work</p> <pre><code> function Thankyou() { alert("Sent to the printing holding queue, you may close this app now or carry on using this app, your work will still print out "); //location.href = 'index.xhtml'; var x = document.forms["myForm"]["Copies"].value; if (x === "0" || x === "") { alert("First name must be filled out"); return false; } } </code></pre> <p>EDIT 2</p> <p>the function is being called </p> <pre><code> function validateForm() { alert("test"); var x = document.forms["myForm"]["fname"].value; if (x === "0" || x === "") { alert("First name must be filled out"); return false; } } </code></pre> <p>but is still not validating my spinner :(</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