Embedding JavaScript



Embedding Inline

You can embed javascript directly inline using an attribute

<body onload="window.alert("message");"> 

or

<body> 
   <script>
      window.alert("message");
   </script>
</body>


Embedding Script Tags

This can be either in the <head> or in <body>

<!DOCTYPE html> 
<head>
<script type="text/javascript">
   function MyFun() {
      var myValue = document.getElementById('myBox').value;
      if (myValue.length == 0) {
         alert("blank box");
      }
   }
</script>
</head/>
<body>
   <input type="text" id="myBox">
   <input type="submit" value="Press" onclick="MyFun()"/>
</body>



© 2023 Better Solutions Limited. All Rights Reserved. © 2023 Better Solutions Limited TopPrevNext