Java Script
By using Html We will design only Static Web Pages. We can not hide any data. This Problem is
Solved by Java Script.
We will write code in between
<script type= ”text/javascript” >
</script>
We can Write script tag in Either Head or Body Part of code.
Java Script Output
1) Document.write(“Hello”);
2) innerHTML
3) Window.alert(“Hello”)
Basic code
<html>
<head>
<script type=”text/javascript”>
Document.write(“Hello I am from Java Script”);
</script>
</head>
</html>
2)
<html>
<head>
</head>
<body>
<h1 Id=”special” > </h1>
<script type=”text/javascript”>
document.getElement ById(“special”).innerHTML=”This is inner HTML Part”;
</script>
</body>
</html>
Window.alert
<html>
<head>
</head>
<body>
<script type=”text/javascript”>
Window.alert(“Click Ok”);
</script>
<h1 Id=”special” >Hello </h1>
<h1> Id=”normal”>Welcome</h1>
</body>
</html>
Comments in Java Script
// for single line
/* */ for multiple lines
Variables and Datatypes in JS
Var a=2;
Var b = ”string”;
Var c = true;// Boolian
Var d = new array(…..) // array
Support datatypes in js: number, string, boolian, arrays, undefined, null
Pop up Boxes in JS
1. Alert Box
Window.alert(“Alert Message”)
2. Conform Box
Window.conform(“confirm message”)
3. Prompt Box
Window.prompt(“Input Message”)
<!DOCTYPE html>
<html>
<body>
<h2>JavaScript Functions</h2>
<p>This example calls a function to convert from Fahrenheit to Celsius:</p>
<p id="demo"></p>
<script>
function toCelsius(f) {
return (5/9) * (f-32);
document.getElementById("demo").innerHTML = toCelsius(77);
</script>
</body>
</html>