Place the following code in the body of your HTML document. (Remove the alert box if you like.):
<form>
<input type = ”button” value = “Click here to check the weather” onClick = “confirm(`Its
sunny today ‘ ) ; ” >
</form> (more…)
Place the following code in the body of your HTML document. (Remove the alert box if you like.):
<form>
<input type = ”button” value = “Click here to check the weather” onClick = “confirm(`Its
sunny today ‘ ) ; ” >
</form> (more…)
An alert box is a small window that pops up with a yellow warning sign and a (usually) important message. With JavaScript we can either show a message to the user either before a page loads or in response to a user action. Here we will make an alert box that appears before the page loads. It will look like this: (more…)
<script language=”JavaScript”>
<!–
document.writeln(”Hello, welcome to my page.” );
//–>
</script>
Insert the above into your html document between the <body> and </body> tags. The piece of text (known as a string) between the parentheses is the parameter given to the writeln() method. The browser will display the HTML between the parentheses when it runs the script. (more…)
Some older browsers do not recognize JavaScript. These browsers would sometimes display JavaScript code in the page as if it were part of the contents of the page. Therefore, it is conventional to place JavaScript code between comment tags as follows:
Older browsers would just ignore the Javascript code between the <!– and –> comment tags, while new browsers would recognize it as JavaScript code. The // just before the end comment tag –> is a JavaScript comment symbol, and tells the browser not to execute the end comment tag –> as JavaScript. Using comment tags makes a webpage more accessible to older browsers.