dominic van hasselt dominic van hasselt - 1 month ago 11
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">
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<form name="registerform" onsubmit="return validateForm()">
First name:<br>
<label>
<input type="text" required="required" name="getfirstname">
</label><br>
Last name:<br>
<input type="text" required="required" name="lastname"><br>
Email address:<br>
<input type="email" required="required" name="email"><br>
Password:<br>
<input type="password" required="required" name="password"><br>
Password2:<br>
<input type="password" required="required" name="password2"><br>
<input type="submit" value="Submit">
</form>


and


window.validateForm=function() {

alert(document.forms["registerform"]);
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;
}</script>
</body>
</html>


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

But when I put

<script>"/JS/Form.js"</script>


it doesn't work...

Any idea?

Answer

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).

Try

<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.