dominic van hasselt dominic van hasselt - 9 months ago 37
HTML Question

How can my html not read my js

This is just 1 html file but whenever I seperate them I have

<html lang="en">
<meta charset="UTF-8">
<form name="registerform" onsubmit="return validateForm()">
First name:<br>
<input type="text" required="required" name="getfirstname">
Last name:<br>
<input type="text" required="required" name="lastname"><br>
Email address:<br>
<input type="email" required="required" name="email"><br>
<input type="password" required="required" name="password"><br>
<input type="password" required="required" name="password2"><br>
<input type="submit" value="Submit">


window.validateForm=function() {

var x = document.forms["registerform"]["password"].value;
var y = document.forms["registerform"]["password2"].value;
if (y != x){
alert("The passwords do not match. Please try again!");
return false;
return true;

When I got the full js just under my form, it does execute the script.

But when I put


it doesn't work...

Any idea?

Answer Source

I would assume that you want to load your javascript file from a relative path (relative to your html page) rather than an absolute path. Absolute paths start with a / (slash).


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

To debug it right click your page and click on the javascript src value. A page with the file content gets shown. It will tell you if the src does not point to an actual file available on your server.