SQL PHP HTML ASP JavaScript articles and free scripts to download

JavaScript code inside HTML tags.

JavaScript is a client side code runs by the user's web browser. How to add JavaScript code to our HTML pages? You must have seen our structure of a simple html code. As html is a set of tags to format our web page, similarly we can use <script> tag to execute any script. To run our JavaScript code the client browser script execution setting must be enabled.

As we are keeping our JavaScript code inside html pages by using <script> tag, it is upto us to keep our code in any location. However if we want our code to work as soon as the page loads, then we have to keep our JavaScript code inside <head> tag. Here is an sample of simple JavaScript code kept inside head tag.

<html>
<head>
<title>Javascript page structure</title>

<script language='JavaScript' type='text/JavaScript'>
document.write("Hello World")
</script>

</head>
<body>
This is body content
</body>
</html>

The above code will write Hello World as soon as the page loads to the client browser. We can keep the script inside our body tag also . Like this

<html>
<head>
<title>Javascript page structure</title>

</head>
<body>
This is body content
<script language='JavaScript' type='text/JavaScript'>
alert("Hello World")
</script>


</body>
</html>

Let us change this a bit and use one alert message inside a function. Like this.

<html>
<head>
<title>Javascript page structure</title>
<script language='JavaScript' type='text/JavaScript'>
function start(){
alert("Hello World")
}
</script>

</head>
<body >
This is body content

</body>
</html>

You can see above code will not display the alert message because we have kept the message inside a function and we need to call the function. To call the function onload we have to use the body tag like this.

<body onload=start();>


Google+

mari08-02-2010
i need validation for name, email, phone number...
shushrita01-09-2013
'text/JavaScript'.This is no longer required. JavaScript is the default scripting language in all modern browsers.
Post Comment This is for short comments only. Use the forum for more discussions.
Name
Email( not to be displayed)Privacy Policy
1+2=This is to prevent automatic submission by spammers. Please enter the result of the sum as asked

JavaScript Basic functions
Variables
Functions
Detecting Browser type



Join Our Email List
Email:  
For Email Newsletters you can trust
HTML . MySQL. PHP. JavaScript. ASP. Photoshop. Articles. FORUM Contact us

©2000-2014 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer