javascript无法正常运行和验证的问题

时间:2013-04-19 22:17:02

标签: javascript jsf

我正在尝试使用javascript来验证一些输入,它没什么大不了的,只是认为这对我的JSF项目来说是个不错的点睛之笔

支持bean已经验证不接受任何小于1的输入,超过50,我想使用JS,因为我必须使用它,为用户提供此信息会很好

我有:

<h:body>
 <h:form id="myForm" onsubmit="return validateForm()"> 
  <p>
   Number of copies (Max of 50) :
   <p:spinner id ="Copies" min="1" max="50" value="#{printerSettings.p}" size ="1"> 
   <!-- 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 -->
   <p:ajax update="p"/>
  </p:spinner>
  <div class="whiteSpace"/>   
  <h:outputText value="Copies that will be printed: &nbsp; #{printerSettings.p}" id="p"/>
 </p>

.............

 </div>
 <script type="text/javascript">
  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;
   }
  }

但是按下提交按钮时

<p:commandButton  
 type="submit" 
 action="#{email.mail(printerSettings.t, printerSettings.p, printerSettings.paperSize, printerSettings.duplex, printerSettings.orienation, printerSettings.printer)}" 
 onclick="Thankyou()" 
 value="Print" />

它不会验证或显示javascript

javascript试图做的只是确保微调器中的值在1到50之间

任何想法?

修改

我已将代码添加到此javascript中,我知道该消息在显示消息时被调用,即使这里的代码仍然无法正常工作

            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;
                }
            }

编辑2

正在调用该函数

            function validateForm()
            {
                alert("test");
                var x = document.forms["myForm"]["fname"].value;
                if (x === "0" || x === "")
                {
                    alert("First name must be filled out");
                    return false;
                }
            }

但仍未验证我的微调器:(

0 个答案:

没有答案