0

I'm new to HTML and developing and login form. Please find below the code I used. I want to import my JavaScript code into HTML form.please help me.

C:\Program Files\xampp\htdocs\forsiteSystem\thems\js\validation.js

 function validateForm()
{
var x=document.forms["login"]["email"].value;
if (x==null || x=="")
  {
  alert("Email must be filled out");
  return false;
  }
} 

C:\Program Files\xampp\htdocs\forsiteSystem\thems\login.html

<html>
        <head>
            <title>Login form</title>
            <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
            <script src="js/validation.js">
            </script>
        </head>
        <body>
            <div>
                <form name="login" action="" method="post" onsubmit="return validateForm()">
                    Email: <input type="text" name="email"><br>
                    password: <input type="text" name="pass"><br>
                    <input type="submit"  id="Submit_button" >
                </form>
            </div>
        </body>
    </html>
1
  • In login.html, you're not closing the meta tag, is that normal? Commented Jan 10, 2014 at 10:38

5 Answers 5

3

Include your js file properly like this:

<script src="js/validation.js">

This code works for me.try

<html>
        <head>
            <title>Login form</title>
            <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
            <script src="js/builder.js">
            </script>
        </head>
        <body>
            <div>
                <form name="login" action="" method="post" onsubmit="return validateForm()">
                    Email: <input type="text" name="email"><br>
                    password: <input type="text" name="pass"><br>
                    <input type="submit"  id="Submit_button" >
                </form>
            </div>
        </body>
    </html>

Your js file will be on same directory under js file with this name builder.js. Code in js file is :

function validateForm()
{
var x=document.forms["login"]["email"].value;
if (x==null || x=="")
  {
  alert("Email must be filled out");
  return false;
  }
} 
Sign up to request clarification or add additional context in comments.

7 Comments

im verry sorry to say still it doesn't work for me .
what is your file hierarchy ?
C:\Program Files\xampp\htdocs\forsiteSystem\thems\js\validation.js C:\Program Files\xampp\htdocs\forsiteSystem\thems\login.html
Did you use my js or your own ? and how you include js
your js. i have included login.html <script src="js/validation.js"> </script>
|
1

This tag should work:

<script src="js/validation.js"></script>

Comments

0

Script path should be.

<script src="js\validation.js"></script>

1 Comment

please check the path you used as src
0

Js path shoulb be js/validation.js

<html>
    <head>
        <title>Login form</title>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <script src="js/validation.js" type="text/javascript">
        </script>
    </head>
    <body>
        <div>
            <form action=".\login.php" method="post" onsubmit="return validateForm()">
                Email: <input type="text" name="email"><br>
                password: <input type="text" name="pass"><br>
                <input type="submit"  id="Submit_button" >
            </form>
        </div>
    </body>
</html>

Comments

0

this is how you can add js correctly

<script type="text/javascript" src="js/validation.js"></script>

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.