Announcement Announcement Module
Collapse
No announcement yet.
xhtml include javascript Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • xhtml include javascript

    Hi,
    Nowadays I'm trying use spring in my project. When I porting my old jsp/html/javascript to new xhtml/jsp/jstl springframework based application, I met a frustrate question. I spend a whole night but failed to solve it.

    First I create a javascript file,named formvalidation.js

    HTML Code:
    function formValidate(){
      alert("formValidate");
    }
    Then I create a xhtml based JSP named register.jsp to include the file and use the function by Form's onsubmit function.

    Code:
    <?xml version="1.0" encoding="UTF-8" ?>
    <%@ page language="java" contentType="text/html; charset=UTF-8"
        pageEncoding="UTF-8"%>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>Insert title here</title>
    <script type="text/javascript" src="formvalidate.js"></script>
    <script type="text/javascript">
       function validate(){
         alert("call formValidate begin");
         formValidate();
         alert("call formValidate end");
       }
    </script>
    </head>
    <body>
    <form onsubmit="validate()">
      <input type="submit" value="submit" />
    </form>
    </body>
    </html>
    When I click the submit button on either firefox or IE,
    "call formValidate begin" OK,
    "call formValidate end" FAILED.
    IE give a tip that the line formValidate(); is a syntax error.

    Thanks in advance, Spring forum.

  • #2
    I see in your comment that you created a file called "formvalidation.js", but that in your in script tag you called it "formvalidate.js" ...

    there's also the possibility that your webroot is not the same. Are you sure both files, the .jsp and the .js are in the same web directory?

    Comment

    Working...
    X