Embedding JavaScript

Embedding Inline

You can embed javascript directly inline using an attribute

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



Embedding Script Tags

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

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

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