title: how to call an external javascript method from a form?
body: <p>I want to submit a form. But before that I wanna validate it. The validation is a javascript method. everything is ok as long as the javascript method is in the  same .jsp file as the form.</p>
  
  <p>But I want to put it to an external javascript file, and the method gets never called. Why?</p>
  
  <p>this part should include the javascript into .jsp file. </p>
  
  <pre><code>  &lt;script type="text/javascript" src="Validate.js"&gt;
      var val = new Validate();
      var result= val.validateArticle();
  &lt;/script&gt;
  </code></pre>
  
  <p>here is the form I want to submit:</p>
  
  <pre><code>&lt;form name="articleAnswerForm" action="answer.html"
          action="answer.html" onsubmit="return result" method="post"&gt;
          Was is der Artikel?&lt;br&gt; &lt;select name="art"&gt;
              &lt;option&gt;???&lt;/option&gt;
              &lt;option&gt;der&lt;/option&gt;
              &lt;option&gt;die&lt;/option&gt;
              &lt;option&gt;das&lt;/option&gt;
          &lt;/select&gt; &lt;input type="hidden" name="richtig" value="${selected.article}"&gt;
          &lt;h1&gt;${selected.german}&lt;/h1&gt;
          &lt;input type="submit" value="Antworten"&gt;
      &lt;/form&gt;
  </code></pre>
  
  <p>The Validate.js is in the same directory as the .jsp file.
  here is the Validate.js (but it works fine, if it is in the .jsp file.)</p>
  
  <pre><code>function validateArticle() {
      var a = document.forms["articleAnswerForm"]["art"].value;
      var richtig = document.forms["articleAnswerForm"]["richtig"].value;
      if (a == null || a == "" || a != richtig) {
          alert("Nein " + a + " ist falsch");
          return false;
      }
  }
  </code></pre>
  
  <p>so far the only thing that works is if I put everything into one .jsp file like below</p>
  
  <pre><code>    &lt;script type="text/javascript" &gt;
  function validateArticle() {
      var a = document.forms["articleAnswerForm"]["art"].value;
      var richtig = document.forms["articleAnswerForm"]["richtig"].value;
      if (a == null || a == "" || a != richtig) {
          alert("Nein " + a + " ist falsch");
          return false;
      }
  }
  &lt;/script&gt;
  </code></pre>
  
  <p>
      </p>
  
  <pre><code>    &lt;form name="articleAnswerForm" action="answer.html"
          action="answer.html" onsubmit="return validateArticle()" method="post"&gt;
          Was is der Artikel?&lt;br&gt; &lt;select name="art"&gt;
              &lt;option&gt;???&lt;/option&gt;
              &lt;option&gt;der&lt;/option&gt;
              &lt;option&gt;die&lt;/option&gt;
              &lt;option&gt;das&lt;/option&gt;
          &lt;/select&gt; &lt;input type="hidden" name="richtig" value="${selected.article}"&gt;
          &lt;h1&gt;${selected.german}&lt;/h1&gt;
          &lt;input type="submit" value="Antworten"&gt;
      &lt;/form&gt;
  
      &lt;form:form method="post" action="word.html"&gt;
          &lt;input type="submit" value="nächste Wort"&gt;
      &lt;/form:form&gt;
  &lt;/c:if&gt;
  </code></pre>
  
  <p></p>