Why no file not found error and purpose of checkJS function

Hi,

I have written the following code from a Php book:

<!DOCTYPE html>
<html lan="en">
<head>
<title>Dog Object</title>
<script src="validator.js"></script>
<style type="text/css">
#JS { display:none; }
</style>
<script>
function checkJS() {
document.getElementById('JS').style.display = "inline";
}
</script>
</head>
<body onload="checkJS();">
<h1>Dog Object Creater</h1>
<div id="JS">
</div>
<noscript>
<div id="noJS">
</div>
</noscript>
</body>
</html>

The output is:

Dog Object Creater

I have 2 questions:

  1. This program uses validator.js file.I don’t have validator.js file. Why I am not getting file not found error?
    2)The above program has checkJS() function. What is the purpose of checkJS function?
    Somebody please guide me.

Zulfi.

Hi @Zulfi6000, you should see a not found status code in the network panel of the browser dev tools though.

Something like this is usually done to add a js-enabled class (or similar) to the body, so that you can account for deactivated JS in your CSS – show a “please enable JS” message if it is missing, for example. I don’t see much purpose in just displaying an empty div though.

1 Like

Hi,
I saw the name Validator.js in one message. One example error message is:

GEThttp://localhost/validator.js
[HTTP/1.1 404 Not Found 0ms]

For this I pressed: CTRL+SHIFT+J

Thanks.
God blesses you.
Zulfi.

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.