answersLogoWhite

0


Best Answer

Javascript inside html

<html>

<head>

<script type="text/javascript" language="javascript">

// Java script code here

</script>

<body>

// html code here

</body>

</html>

Via External Link:

<html>

<head>

<script type="text/javascript" language="javascript" src="location of js file">

</script>

<body>

// html code here

</body>

</html>

User Avatar

Wiki User

12y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

12y ago

There are two ways to include the javascript

1. Inline JavaScript i.e when you are defining your script in HTML page itself.

<script type="text/javascript" language="JavaScript">

...

js code

</script>

2. As external reference

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

This answer is:
User Avatar

User Avatar

Wiki User

11y ago

The correct way to include JavaScript in HTML is to use the SCRIPT element. Then you can either enter your JavaScript code directly inside the element, or use the elements SRC attribute to load JavaScript code from an external file.

For instance:

<script type="text/javascript">

//JS code here

</script>

Or:

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

Including scripts that are reused is good practice as it allows the browser to cache them, keeping it from having to load the same script again and again. In most instances, it is also best practice to include your SCRIPT elements at the end of your document's BODY element. This keeps the scripts low on the page, and makes for better search engine optimization.

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: How do you put java script into HTML?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

What does it mean to do HTML submit?

HTML means Hypertext Markup Language. The tag is used for various javascripts and Java programs. HTML submit is a form of a script in Java programming.


Does HTML code work in java script?

Yes it does. That is how client side validation of html control is possible using javascript


How can we use script tag in java?

to implement javascript embed the statements between &lt;script&gt; n &lt;/script&gt;,,, and include any scripting language. eg:&lt;script LANGUAGE="javascript"&gt; block of codes &lt;/script&gt;


What is embedding java script?

To embed JavaScript code is to include it in the HTML page. For example, this will embed the code to display an alert: &lt;script type="text/javascript"&gt; alert("Embedded alert!"); &lt;/script&gt;


What is the difference between script and scriptlet?

"script" is an HTML tag used to include JavaScript on a web page. Example: &lt;HTML&gt; &lt;body&gt; &lt;script type="text/javascript"&gt; document.write("hi there"); // javascript interpreted by the browser &lt;/script&gt; &lt;/body&gt; &lt;/HTML&gt; "Scriptlet" is a JSP construct used to include Java in a JSP page. Example: &lt;HTML&gt; &lt;body&gt; &lt;% // this is a scriptlet response.getWriter().write("hi there"); // Java executed on the server %&gt; &lt;/body&gt; &lt;/HTML&gt; Here the result (an HTML document with the text "hi there") is the same in both cases, but the mechanisms are different - Javascript runs in the browser (any browser), while the JSP scriptlet is executed on the server and needs a server with JSP support. See related links.

Related questions

What is java script code for password?

There is an html form element for password. Validation script for password doesn't differ from script of html text element


How do you restrict no of characters in text box in HTML?

by using java script


What should you known to study java script?

Xhtml/html &amp; css


What is used to create large program on internet?

Java script


What does it mean to do HTML submit?

HTML means Hypertext Markup Language. The tag is used for various javascripts and Java programs. HTML submit is a form of a script in Java programming.


How does java script ehance the capabilites of HTML?

Javascript can change how HTML will work, alike how CSS makes HTML look flashy.


How can you designing a web?

You can design a websites with the help of HTML,CSS and Java Script.


How can you include imagesw using HTML and java script?

&lt;img src="img.jpg" /&gt;


Does HTML code work in java script?

Yes it does. That is how client side validation of html control is possible using javascript


Is HTML and java script the same?

Nope. Not the way I look at it. I would have used java script in web design for some graphic work but java is the king and I also heard that java script really is not all the same now days. But I would say "NO" anyhow. Cheers linny


How do you write javascript codes for website on a mac?

You can write java script code on any platform be it mac, linux, solaris or windows. All you need is a mac version of notepad, some html page where you insert your java script code and a web browser where you view the html page. All major browsers support java script coding and all you need to do is enable the Java Script support in browsers if it is not enabled already.


What is the definition of java script?

(A scripting language that is added to standard HTML to create interactive documents.