Javascript Lab Programs
Javascript Lab Programs
<html>
<head>
</head>
<body>
<label>Enter the first number
<input id="num1">
</label>
<br><br>
<label>Enter the Second number
<input id="num2">
</label>
<br><br>
<button onclick="swap()">
Swap
</button>
<input id='sum'>
<script>
function swap() {
var x, y, z,m;
x = Number( document.getElementById("num1").value );
y = Number( document.getElementById("num2").value );
z= x;
x=y;
y=z;
m=x+y;
// Comment the code section
document.getElementById("sum").value = m;
document.getElementById("num1").value = x;
document.getElementById("num2").value = y;
}
</script>
</body>
</html>
Output :
Output :
Output
}
</script>
</head>
<body>
<label>Enter the String <input id="str1"> </label>
<br><br>
<label>Enter the Character <input id="cha"> </label>
<br><br>
<label>Number of Occurences is <input id="str2"> </label>
<button onclick="checkChar()"> Check </button>
</body>
</html>
Output :
Program No: 5 Write a java script program to pass a 'javascript function' as parameter.
<html>
<head>
<meta charset="utf-8">
<title>JavaScript program to pass a JavaScript function as parameter</title>
<script>
function addStudent(id, refreshCallback)
{ document.write("The id of the student is "+id+" ");
refreshCallback();
}
function refreshStudentList() {
document.write("Aakash");
}
addStudent(101, refreshStudentList);
</script>
</head>
<body>
</body>
</html>
OUTPUT: