title: The entity name must immediately follow the '&' in the entity reference
body: <p>I have the following simple Javascript code that allows only digits to be entered into the specified <code>TextField</code>. I have used it earlier in many places such as Servlet, JSP, JSTL/EL and even in PHP and it worked fine as expected. In JSF however, I less concerned with Javascript in which some characters need to be escaped. I tried my best to get it run but I couldn't. Here is the Javascript code along with JSF stuff.</p>
  
  <pre><code>&lt;?xml version='1.0' encoding='UTF-8' ?&gt;
  
  &lt;html xmlns="http://www.w3.org/1999/xhtml"
       xmlns:h="http://java.sun.com/jsf/html"
       xmlns:f="http://java.sun.com/jsf/core"&gt;
  
  &lt;h:head&gt;
   &lt;title&gt;Demo&lt;/title&gt;
  
   &lt;script type="text/javascript" language="javascript"&gt;
  
       $(document).ready(function()
       {
           $("#myForm:txtDemo").keypress(function(event)
           {
               if (event.keyCode==46 || event.keyCode==8|| event.keyCode==9 || event.keyCode&gt;=35 &amp;&amp; event.keyCode&lt;=40)
               {
                   // let it happen, don't do anything
               }
               else
               {
                   if (event.charCode&lt;48 || event.charCode&gt;57 || event.charCode==16)
                   {
                              event.preventDefault();
                   }
               }                    
           });
       });
  
   &lt;/script&gt;
  
  &lt;/h:head&gt;
  
  &lt;h:body&gt;
      &lt;h:form id="myForm"&gt;
  
          &lt;br/&gt;&lt;br/&gt;&lt;br/&gt;
          &lt;h:inputText id="txtDemo" required="true" requiredMessage="Mandatory." validatorMessage="The field should contain al least 10 digits"&gt;
              &lt;f:validateLength maximum="10" minimum="2"/&gt;
              &lt;f:validateRegex pattern="[0-9]*"/&gt;
              &lt;f:ajax event="valueChange" execute="txtDemo msg" render="txtDemo msg"/&gt;
          &lt;/h:inputText&gt;&lt;br/&gt;
  
          &lt;h:message id="msg" for="txtDemo" showDetail="true" style="color:red"/&gt;&lt;br/&gt;
  
          &lt;h:commandButton id="btnSubmit" value="Submit"/&gt;
  
      &lt;/h:form&gt;
  &lt;/h:body&gt;
  </code></pre>
  
  <p></p>
  
  <hr>
  
  <p>Javascript is not being compiled. It parses the following error.</p>
  
  <pre><code>An Error Occurred:
  
  Error Parsing /Restricted/TempTags.xhtml: Error Traced[line: 14] The entity name 
  must immediately follow the '&amp;' in the entity reference.
  </code></pre>
  
  <hr>
  
  <p>I have even placed the Javascript code in a separate <code>js</code> file and included that file in this page. I have also replaced <code>&lt;script&gt;&lt;/scrip&gt;</code> with <code>&lt;h:outputScript&gt;&lt;/h:outputScript&gt;</code> still the same problem remains.</p>
  
  <hr>
  
  <p>I have also tried the following to see whether the Javascript function is being called or not using <code>alert();</code> removing the error parsing code from the function but the function itself wasn't even called and the alert message wasn't displayed.</p>
  
  <pre><code>&lt;script type="text/javascript" language="javascript"&gt;
  
       $(document).ready(function()
       {
           $("#myForm:txtDemo").keypress(function(event)
           {
               alert();
           });
       });
  
  &lt;/script&gt;
  </code></pre>
  
  <hr>
  
  <p>Which necessary changes are required in that Javascript to get it run as expected?</p>