Click here to Skip to main content
15,879,535 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
If i missed to give curly brackets for a javascript function in html file don't show error in HTML validator as like C compiler?

What I have tried:

Why below code does not show error in HTML validator [like https://html5.validator.nu]?[^] You can see i have mistakenly missed the enclosing curly bracket of function substitute().As you know in C/CPP programming compiler will say error if any function ending curly braces missed by a programmer.
Like that is any tool/ html validator there to tell about the same about missing curly braces for my example code?

HTML
<!DOCTYPE html>
<html> 
<head>
  <title>JavaScript Example</title> 
  <script type="text/javascript">
    function substitute() {
       var myValue = document.getElementById('myTextBox').value;
        
       if(myValue.length == 0) {
	  alert('Please enter a real value in the text box!');
          return;
       }
       var myTitle = document.getElementById('title');
       myTitle.innerHTML = myValue;
   </script>
</head>
<body>
  <h1 id="title">JavaScript Example</h1>

  <input type="text" id="myTextBox" />
  <input type="submit" value="click me" />
</body>
</html>
Posted
Updated 27-Aug-16 21:48pm
v4
Comments
Peter_in_2780 28-Aug-16 3:22am    
An HTML validator doesn't care what is between the <script> ... </script> tags (as long as it's not more HTML tags). You need to look for a javascript validator - something like JSLint - to check your script.

1 solution

As the name suggests, that is an HTML validator and would only look for the HTML syntax errors and bad practices. Whereas, what you are looking for is JavaScript validator, try JSLint[^]. I entered your JavaScript code there,
JavaScript
function substitute() {
       var myValue = document.getElementById('myTextBox').value;
        
       if(myValue.length == 0) {
	  alert('Please enter a real value in the text box!');
          return;
       }
       var myTitle = document.getElementById('title');
       myTitle.innerHTML = myValue;

Have a look at the errors, there are 6 of them already in the bottom of the page and also, it also tells that JavaScript engine was expecting a } but found end.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900