Technology TidBits

Answers to various technical questions on php programming, mysql, linux, and many more categories.
25% off Hosting at HostGator.com:
Use Code techbits25



How to include Javascript into your html code

Last updated: 05/21/2012

You can very easily integrate java script into your html pages. Most of the browsers on the Internet support java script.

 

One of the most important things, which is required on the Internet, the Navigation can be done with the help JavaScript. These scripts are called the navigational scripts and they are used for navigating from one page to another. These scripts help your visitors to move around your website with the help of menu lists and buttons.

 

Let us study one example, which helps us to move behind on the previous and the next page of your browser.

 

Example

 

<HTML>

<HEAD>

</HEAD>

<BODY>

<FORM METHOD="post">

 

<INPUT TYPE="button” VALUE="Move Back" OnClick="history.go( -1 ); return true;">

 

<INPUT TYPE="button” VALUE="Move Back” OnClick="history.go(  1 );return true;">

 

</FORM>

</BODY>

</HTML>

 

External Java Script

 

 

You can also use the above script in an external file. But there are certain important things you need to keep in mind about external java script usage are as follows.

 

1. External JavaScript files can be used on many pages but you do not need to write one for each page so basically you are writing once and using it on multiple pages and hence has lots of code reuse.

 

2. You can have both types of scripts in the external file head scripts and body scripts.

 

3.Script file should not contain the script tag.

 

4.You do not want your code to be visible or you want to use it on multiple pages then you can also create an external java script file.

 

Procedure To Create An External Java Script File.

 

 

  1. Click on notepad
  2. Type the JavaScript code and save the file with extension js
  3. For calling the script you can use the code below.

 

<script type="text/javascript" src="xxx.js">

</script>

 

Conclusion

 

The reuse of the code is one of the most important things of java script. Along with the navigation part the code reuse becomes a very important feature of JavaScript.

 

 

blog comments powered by Disqus
Have your own Tech-bit to contribute? Submit it here

Other questions in this category:
How can I open a new window using Javascript?
How can I add a quick javascript error page to my cgi / php scripts
How can I validate a form that has brackets in the variable names?
Why do my web forms lose data when I hit the back button?
How to refresh the parent window from a pop up window.
How can I submit data to a form from a pop-up window?
Configuring htmleditor to do file uploads using php
How can I easily hide / display a form or text on my website?
IE 7 gives me an "Unknown runtime error" when using ajax - how can I fix this?
How can I refresh the parent window from a pop-up



Powered by KnowledgebasePublisher 1.1
Host Gator
Content provided by Roberts WebForge, Inc.