0

I have a javascript file in web/js/Validation.js directory. In my Login.jsp, I am calling this .js file to validate username. This does not seem to be working, please can you help.

I've tried using src="/js/Validation.js" and even changing script tag location (ie. between html and head tags) without any luck.

thanks.

Validation.js

    function simple_Validation()
    {

    var valid = true;

    if (document.login_form.user.value.lenght == 0)
    {
     alert ("Pleaes type username"); 

      valid = false;
    }

    return valid;
    }

Login.jsp

    <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
        pageEncoding="ISO-8859-1"%>
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
    <%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <script type="text/javascript" src="js/Validation.js">

    </script>

    <title>Login</title>

    </head>
    <body>

        <form name="login_form" action="LoginServlet" method="post"
            onSubmit="return simple_Validation();">
            <table border="0">
                <tr align="left" valign="top">
                    <td>User Name:</td>
                    <td><input type="text" name="user" class="inputbox" /></td>
                </tr>
                <tr align="left" valign="top">
                    <td>Password:</td>
                    <td><input type="password" name="pass" class="inputbox" /></td>
                </tr>
                <tr align="left" valign="top">
                    <td></td>
                    <td><input type="submit" name="submit" value="Login" /></td>
                </tr>
            </table>
            <c:out value="${loginresult}">
            </c:out>

        </form>
    </body>
    </html>
4
  • 3
    You spelled length wrong in your example. Commented Sep 16, 2012 at 15:37
  • Did you try alerting something inside of the function to make sure the JS file is referenced correctly and the function is being called? If you can confirm it's being called, then it's problem the spelling problem that @marteljn noticed Commented Sep 16, 2012 at 15:54
  • 2
    Is your JS file being loaded? E.g. do you see a 404 for that file in Firebug (or Chrome inspector, etc)? If not then its a JS issue, what output do your see in Firebug/Chrome console output? Commented Sep 17, 2012 at 0:56
  • thanks for your response Guys. Yes, the problem was with my spellings. Commented Sep 18, 2012 at 12:21

2 Answers 2

1

We have come a long way in javascript technology and we have a lot of tools to debug javascript (unlike putting a lot of s, though I think this is by far the simplest and best ;-)) which are easy to use and guess what? Some are free!

So one such tool (probably one of the best) is which comes as an add-on for .

, & has some built-in developer tools, they appear when you press F12 on your PC (on Mac I am not sure :-))

So here are some steps:

  1. Install Firefox
  2. Install firebug
  3. Load your page
  4. Enable firebug for your page. Enable scripting panel
  5. Reload your page
  6. Check if the file is loaded properly (taken from nickdos's comment)
  7. Check if there is some javascript error (probably the spelling of length taken from marteljn's comment)
Sign up to request clarification or add additional context in comments.

Comments

0

in your javascript you have mispelled length as lenght.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.