HTML JavaScript

HTML JavaScript: A script is a small program which is used to make webpages look attractive and dynamic. And you can also create an alert and a popup window with a  mouse click.  At present, the most popular scripting language is JavaScript and it is used for websites.

HTML JavaScript

And the <script> tag is sued to define the client-side script.

Example:



<!DOCTYPE html>  
<html>  
<body>  
<h1>JavaScript Date and Time example</h1>  
<button type="button"  
onclick="document.getElementById('demo').innerHTML = Date()">  
Click me to display Date and Time.</button>  
<p id="demo"></p>  
</body>  
</html>

HTML <script> Tag

The script tag is used to define the client-side script. It may be an external (or) internal javascript which contains scripting statements. It is mainly used for manipulating images, from validation and change content by dynamically.

<!DOCTYPE html>  
<html>  
<body>  
<h2>Use JavaScript to Change Text</h2>  
<p id="demo"></p>  
<script>  
document.getElementById("demo").innerHTML = "Hello freshersnow";  
</script>  
</body>  
</html>

List of event attributes

Event Name Handler Name Occur
on Blur blur when it forms input loses focus
onClick click When the user clicks on a form element or link
onSubmit submit When a user submits a form to the server
onLoad load When the page loads on the browser
onFocus focus when a user focuses on an input field
onSelect select When a user selects the form input field

External JavaScript

If you want we can keep our JavaScript code in a separate file and can call in HTML file. And save java external file using .js extension.

Syntax:<script type=”text/javascript” src=”URL “></script>

Example:

<!DOCTYPE html>  
<html>  
   <head>  
    <script type="text/javascript" src="external.js"></script>  
    </head>  
     <body>  
      <h2>External JavaScript Example</h2>  
       <form onsubmit="fun()">  
         <label>Enter your name:</label><br>  
      <input type="text" name="uname" id="frm1"><br>  
       <label>Enter your Email-address:</label><br>    
      <input type="email" name="email"><br>  
      <input type="submit">  
  </form>  
 </body>  
 </html>

HTML noscript Tag

This tag is used to write the disabled script in the browser. And this tag is enclosed as <noscript>….</noscript> tag is not displayed on the browser.

Example:

<!DOCTYPE html>  
<html>  
<body>  
<p id="demo"></p>  
<script>  
document.getElementById("demo").innerHTML = "Hello freshersnow!";  
</script>  
<noscript>This text is not visible in the browser.</noscript>  
</body>  
</html>