Java Script
Java Script
Java Script
<html>
<head>
<script>
function abc()
a=document.getElementById("abc").value;
document.getElementById("xyz").innerHTML=a;
</script>
</head>
<p id="xyz"></p>
</html>
…………………………
<html>
<head>
<script>
function abc()
x=document.getElementById("demo");
x.style.color="red";
</script>
</head>
<body>
<p id="demo">hi</p>
</body>
</html>
……………………
<!DOCTYPE html>
<html>
<head>
<script>
function getValue()
{
var x=document.getElementById("myHeader");
alert(x.innerHTML);
}
</script>
</head>
<body>
</body>
</html>
…………………….
<!DOCTYPE html>
<html>
<body>
<p id="p1">
This is a text.
This is a text.
This is a text.
</p>
onclick="document.getElementById('p1').style.visibility='hidden'">
onclick="document.getElementById('p1').style.visibility='visible'">
</body>
</html>
…………………………..
<!DOCTYPE html>
<html>
<body>
<script>
document.write(document.lastModified);
</script>
</body>
</html>
……………………
<!DOCTYPE html>
<html>
<head>
<script>
function removeOption()
var x=document.getElementById("mySelect");
x.remove(x.selectedIndex);
</script>
</head>
<body>
<form>
<select id="mySelect">
<option>Apple</option>
<option>Pear</option>
<option>Banana</option>
<option>Orange</option>
</select>
</form>
</body>
</html>
…………………………
<!DOCTYPE html>
<html>
<body>
<button type="button"
onclick="document.getElementById('id1').style.color='red'">
Click Me!</button>
</body>
</html>
…………………….
<!DOCTYPE html>
<html>
<body>
</html>
……………………
<!DOCTYPE html>
<html>
<body>
</body>
</html>
……………………..
<!DOCTYPE html>
<html>
<body>
<form>
Buttons:
</form>
function disableElement()
document.getElementById("btn01").disabled=true;
</script>
</body>
</html>
………………………….
<html>
<head>
<script>
function validate()
x=document.myForm
at=x.email.value.indexOf("@")
if (at == -1)
return false
</script>
</head>
<body>
</form>
</body>
</html>
………………………….
<html>
<head>
<script>
function validate()
x=document.myForm
input=x.myInput.value
if (input.length>5)
return false
else
{
return true
</script>
</head>
<body>
</form>
</body>
</html>
………………………………………………
<html>
<head>
<script>
function getText()
var x=document.getElementById("mySelect");
alert(x.options[x.selectedIndex].text);
</script>
</head>
<body>
<form>
<select id="mySelect">
<option>Apple</option>
<option>Orange</option>
<option>Pineapple</option>
<option>Banana</option>
</select>
fruit">
</form>
</body>
</html>
………………………..
<!DOCTYPE html>
<html>
<body>
<button onclick="myFunction()">Click</button>
<script>
function myFunction()
document.getElementById("demo").innerHTML="Hello World";
};
</script>
</body>
</html>
………………….
<!DOCTYPE html>
<html>
<body>
<button onclick="myFunction()">click</button>
<script>
function myFunction()
x.innerHTML=d.getDate();
</script>
</body>
</html>
……………………………
<!DOCTYPE html>
<html>
<head>
<script>
var myWindow;
function openWin()
myWindow = window.open("","myWindow","width=400,height=200");
function closeWin()
if (myWindow)
myWindow.close();
}
function checkWin()
if (!myWindow)
else
if (myWindow.closed)
else
</script>
</head>
<body>
<button onclick="openWin()">Open "myWindow"</button>
<br><br>
<br><br>
<div id="msg"></div>
</body>
</html>
………………………….
<script type="text/javascript">
function changeColor(){
document.getElementById('colorMsg').style.background = newColor;
</script>
background color...</div>
<option value="transparent">None</option>
<option value="yellow">Yellow</option>
<option value="salmon">Salmon</option>
<option value="lightblue">Light Blue</option>
</select>
………………………………………..
<script type="text/javascript">
function showMsg(){
document.getElementById('userMsg').innerHTML = userInput;
</script>
<p id="userMsg"></p>
……………………………..
When text input inside the textbox it will display on thye body of webpage…….
<html>
<head>
<script>
function abc()
a=document.getElementById("abc").value;
document.getElementById("xyz").innerHTML=a;
</script>
</head>
<p id="xyz"></p>
</html>
…………………………
<html>
<head>
<script>
function abc()
x=document.getElementById("demo");
x.style.color="red";
</script>
</head>
<body>
<p id="demo">hi</p>
</body>
</html>
………………
<!DOCTYPE html>
<html>
<head>
<script>
function getValue()
{
var x=document.getElementById("myHeader");
alert(x.innerHTML);
}
</script>
</head>
<body>
</body>
</html>
…………………….
<!DOCTYPE html>
<html>
<body>
<p id="p1">
This is a text.
This is a text.
This is a text.
</p>
onclick="document.getElementById('p1').style.visibility='hidden'">
onclick="document.getElementById('p1').style.visibility='visible'">
</body>
</html>
…………………………..
<!DOCTYPE html>
<html>
<body>
<script>
document.write(document.lastModified);
</script>
</body>
</html>
……………………
<!DOCTYPE html>
<html>
<head>
<script>
function removeOption()
var x=document.getElementById("mySelect");
x.remove(x.selectedIndex);
</script>
</head>
<body>
<form>
<select id="mySelect">
<option>Apple</option>
<option>Pear</option>
<option>Banana</option>
<option>Orange</option>
</select>
</form>
</body>
</html>
…………………………
<!DOCTYPE html>
<html>
<body>
<button type="button"
onclick="document.getElementById('id1').style.color='red'">
Click Me!</button>
</body>
</html>
…………………….
<!DOCTYPE html>
<html>
<body>
</body>
</html>
……………………
<!DOCTYPE html>
<html>
<body>
<h1 onclick="this.innerHTML='Ooops!'">Click on this text!</h1>
</body>
</html>
……………………..
<!DOCTYPE html>
<html>
<body>
<form>
Buttons:
</form>
<script>
function disableElement()
document.getElementById("btn01").disabled=true;
}
</script>
</body>
</html>
………………………….
<html>
<head>
<script>
function validate()
x=document.myForm
at=x.email.value.indexOf("@")
if (at == -1)
return false
</script>
</head>
<body>
</form>
</body>
</html>
………………………….
<html>
<head>
<script>
function validate()
x=document.myForm
input=x.myInput.value
if (input.length>5)
return false
else
return true
</script>
</head>
<body>
<form name="myForm" action="1.html" onsubmit="return validate()">
</form>
</body>
</html>
………………………………………………
<html>
<head>
<script>
function getText()
var x=document.getElementById("mySelect");
alert(x.options[x.selectedIndex].text);
</script>
</head>
<body>
<form>
<select id="mySelect">
<option>Apple</option>
<option>Orange</option>
<option>Pineapple</option>
<option>Banana</option>
</select>
fruit">
</form>
</body>
</html>
………………………
<html>
<head>
<script>
function padding()
document.getElementById('mytable').cellPadding="15";
function spacing()
document.getElementById('mytable').cellSpacing="15";
</script>
</head>
<body>
<table id=mytable border=1>
<tbody>
<tr>
<td>100</td>
<td>200</td></tr>
<tr>
<td>300</td>
<td>400</td></tr></tbody></table>
<form>
</form></body></html>
…………………….
<html>
<head>
<script>
function formSubmit()
document.forms.myForm.submit()
</script>
</head>
<body>
</form>
</body>
</html>
……………………
<html>
<head>
<script>
function formAction()
var x=document.getElementById("mySelect");
x.multiple=true;
</script>
</head>
<body>
<form>
<option>Apple</option>
<option>Banana</option>
<option>Orange</option>
</select>
<input type="button" onclick="formAction()" value="Select multiple">
</form>
</body>
</html>
……………………
<html>
<head>
<script>
function formAction()
var x=document.getElementById("mySelect");
alert(x.form.name);
</script>
</head>
<body>
<form name="ashish">
<select id="mySelect">
<option>Apple</option>
<option>Banana</option>
<option>Orange</option>
</select>
</body>
</html>
………………………..
<html>
<body>
<script type="text/javascript">
document.write("<p>Browser: ")
document.write(navigator.appName + "</p>")
document.write("<p>Browserversion: ")
document.write(navigator.appVersion + "</p>")
document.write("<p>Code: ")
document.write(navigator.appCodeName + "</p>")
document.write("<p>Platform: ")
document.write(navigator.platform + "</p>")
document.write(navigator.cookieEnabled + "</p>")
</script>
</body>
</html>
……………………….
<html>
<head>
<script type="text/javascript">
function formAction()
var x=document.getElementById("mySelect")
x.size="3"
</script>
</head>
<body>
<form>
<select name="mySelect">
<option>Apple</option>
<option>Banana</option>
<option>Orange</option>
<option>Melon</option>
</select>
</body>
</html>
………………………
<html>
<head>
<script type="text/javascript">
function formAction()
var x=document.getElementById("mySelect")
x.remove(x.selectedIndex)
</script>
</head>
<body>
<form>
<select name="mySelect">
<option>Apple</option>
<option>Banana</option>
<option>Orange</option>
</select>
</form>
</body>
</html>
……………………..
<html>
<head>
<script type="text/javascript">
function changeText()
var x=document.getElementById("mySelect")
x.options[x.selectedIndex].text="Melon"
</script>
</head>
<body>
<form>
<select id="mySelect">
<option>Apple</option>
<option>Orange</option>
<option>Pineapple</option>
<option>Banana</option>
</select>
</form>
</body>
</html>
…………………………..
<html>
<head>
<script type="text/javascript">
function getIndex()
var x=document.getElementById("mySelect")
alert(x.selectedIndex)
</script>
</head>
<body>
<form>
<select id="mySelect">
<option>Apple</option>
<option>Orange</option>
<option>Pineapple</option>
<option>Banana</option>
</select>
</form>
</body>
</html>
………………..
<html>
<body>
<script>
if (window.print) {
</script>
</body>
</html>
…………………………………
<!DOCTYPE html>
<html>
<body>
<p id="demo">Click the button to change the text in this paragraph.</p>
<button onclick="myFunction()">Click</button>
<script>
function myFunction()
document.getElementById("demo").innerHTML="Hello World";
};
</script>
</body>
</html>
………………….
<!DOCTYPE html>
<html>
<body>
<button onclick="myFunction()">click</button>
<script>
function myFunction()
var x = document.getElementById("demo");
x.innerHTML=d.getDate();
</script>
</body>
</html>
……………………………
<!DOCTYPE html>
<html>
<head>
<script>
var myWindow;
function openWin()
myWindow = window.open("","myWindow","width=400,height=200");
function closeWin()
{
if (myWindow)
myWindow.close();
function checkWin()
if (!myWindow)
else
if (myWindow.closed)
else
}
</script>
</head>
<body>
<br><br>
<br><br>
<div id="msg"></div>
</body>
</html>
………………………….
<html>
<head>
<script type="text/javascript">
function specifyRow()
var x=document.getElementById('myTable').rows
x[2].height="100"
</script>
</head>
<body>
<tr>
<td>Row1 cell1</td>
<td>Row1 cell2</td>
</tr>
<tr>
<td>Row2 cell1</td>
<td>Row2 cell2</td>
</tr>
<tr>
<td>Row3 cell1</td>
<td>Row3 cell2</td>
</tr>
<tr>
<td>Row4 cell1</td>
<td>Row4 cell2</td>
</tr>
<tr>
<td>Row5 cell1</td>
<td>Row5 cell2</td>
</tr>
</table>
<form>
<input type="button" onclick="specifyRow()" value="Change height of third row">
</form>
</body>
</html>
…………………………
<html>
<head>
<script type="text/javascript">
function getText()
var x=document.getElementById("mySelect")
alert(x.options[x.selectedIndex].text)
</script>
</head>
<body>
<form>
<select id="mySelect">
<option>Apple</option>
<option>Orange</option>
<option>Pineapple</option>
<option>Banana</option>
</select>
</form>
</body>
</html>
…………………
<html>
<head>
<script type="text/javascript">
function changeText()
var x=document.getElementById("mySelect")
x.options[x.selectedIndex].text="Melon"
</script>
</head>
<body>
<form>
<select id="mySelect">
<option>Apple</option>
<option>Orange</option>
<option>Pineapple</option>
<option>Banana</option>
</select>
</form>
</body>
</html>
………………………
<html>
<head>
<script type="text/javascript">
function makeDisable()
var x=document.getElementById("mySelect")
x.disabled=true
function makeEnable()
var x=document.getElementById("mySelect")
x.disabled=false
</script>
</head>
<body>
<form>
<select id="mySelect">
<option>Apple</option>
<option>Banana</option>
<option>Orange</option>
</select>
</form>
</body>
</html>
…………………..
<html>
<head>
<script type="text/javascript">
function formAction()
var x=document.getElementById("mySelect")
x.multiple=true
</script>
</head>
<body>
<p>
Before you click on the "Select multiple" button, try to select more than one option (by holding down
the shift or Ctrl key). Click on the "Select multiple" button and try again.
</p>
<form>
<option>Apple</option>
<option>Banana</option>
<option>Orange</option>
</select>
</form>
</body>
</html>
………………………
<html>
<head>
<script>
function show() {
alert(elem.innerHTML);
</script>
</head>
<body onload="show();">
<h1>Rockbands</h1>
<h2>Beatles</h2>
<ol id="BeatleList">
<li>Paul</li>
<li>John</li>
<li>George</li>
<li>Ringo</li>
</ol>
<h2>Rolling Stones</h2>
<ol id="StonesList">
<li>Mick</li>
<li>Keith</li>
<li>Charlie</li>
<li>Bill</li>
</ol>
</body>
</html>
……………………
<html>
<body>
<p>This example calls a function which performs a calculation,and returns the result:</p>
<p id="demo"></p>
<script>
function myFunction(a,b)
return a*b;
document.getElementById("demo").innerHTML=myFunction(5,5);
</script>
</body>
</html>
…………………….