FSP Js Lab Exp - 100105
FSP Js Lab Exp - 100105
Program Output :
Screen accepting user input for First No.
Result :
(To see the output in the Console, right click mouse button on the browser screen and go to inspect
option)
Program Output :
Program Output :
Program Output :
function myFunction7() {
document.getElementById("demo2").innerHTML = "Welcome to Jamia Polytechnic";
}
function myFunction8() {
document.getElementById("demo3").innerHTML = "Welcome to Computer Dept";
}
</script>
</head>
<body>
<h3>Input Form Events</h3>
Enter your name: <input type="text" id="fname" onblur="myFunction1()"><br>
When you leave the input field, a event onblur is triggered which transforms the input text to upper
case.<br>
Enter your name: <input type="text" id="name" onchange="myFunction2()"><br>
When you leave the input field, a event onchange is triggered which transforms the input text to lower
case.<br>
Enter your name: <input type="text" onfocus="myFunction3(this)"><br>
When the input field gets focus, a event onfocus is triggered which changes the background-color.<br>
Enter some text: <input type="text" value="Hello world!" onselect="myFunction4()">
<p id="demo"></p>
<form>
Write a message:
<input type="text" onkeydown="color('yellow')" onkeyup="color('white')" name="myInput">
</form><br>
<form onsubmit="confirmInput()" action="https://www.jamiapolytechnic.com/">
Enter your name: <input id="fname" type="text" size="20">
<input type="submit"><br>
When we click on submit, an onsubmit event is triggered which redirect to assign website.<br>
</form>
<br>A onkeydown event is triggered when the user is pressing a key in the input field.<br>
Enter some text:<input type="text" onkeydown="myFunction5()"><br>
A onkeydown event is triggered when the user releases a key in the input field. The function
transforms the character to upper case.<br>
Enter your name: <input type="text" id="sname" onkeyup="myFunction6()"><br>
<h3>Click Form Events</h3>
<p id="demo1">This is a paragraph.</p>
<button type="button" onclick="displayDate()">Display Date</button>
<br>Click the button to trigger onclick function.<br>
Click the text to change the color. A function, with parameters, is triggered when the mouse button is
pressed down,<br> and again, with other parameters, when the mouse button is released.</p>
Click somewhere in the document. An alert box will alert the name of the element you clicked on.
<h3>This is a heading</h3>
<img border="0" src="img1.jpg" alt="Nature" width="50" height="70">
<div id="coordiv" style="width:199px;height:99px;border:1px solid"
onmousemove="myFunction(event)" onmouseout="clearCoor()"></div>
<p>Mouse over the rectangle above, and get the coordinates of your mouse pointer.</p>
<p id="demo"></p>
Moves the mouse pointer over the image.<br>
<img onmouseover="bigImg(this)" onmouseout="normalImg(this)" border="0" src="img1.jpg"
alt="Nature" width="50" height="70">
</body>
</html>
Program Output :
Program Output :
Exp 9 : Develop a web page for creating session and persistent cookies. Observer the effect with
Browser cookie setting.
<!DOCTYPE html>
<html lang="en">
<head>
<title>Exp 10</title>
<h3>Creating and Reading cookie</h3>
<script>
function setCookie() {
var name = document.getElementById('person').value
document.cookie = "name=" + name + ";"
alert("Cookie Created")
}
function readCookie() {
var cookie = document.cookie
var panel = document.getElementById('panel')
if (cookie == "")
panel.innerHTML = "Cookie not found"
else
panel.innerHTML = cookie
}
</script>
</head>
<body>
<form name="myForm">
Enter your name <input type="text" id="person" /><br />
<input type="button" value="Set Cookie" onclick="setCookie()" />
<input type="button" value="Read Cookie" onclick="readCookie()" />
<p id="panel"></p>
</form>
//Creating a persistent cookies
<script>
var date = new Date();
var days=2;
date.setTime(date.getTime()+(days*24*60*60*1000));
var expires = date.toGMTString();
document.cookie = "user=Jamia; expires="+ expires + ";"
alert("Cookie Created\n"+document.cookie)
Pathan Firozkhan S. 26 Jamia Polytehnic, Akkalkuwa
Diploma in Computer Engg. Java Script Practical (22519)
</script>
</body>
</html>
Program Output :
Exp 11: Develop a web page for placing the window on the screen and working with child window
<!DOCTYPE html>
<html lang="en">
<head>
<title>Exp 11</title>
<script>
function openWindow() {
myWindow = window.open("https://www.google.com", "My Window", "top=100, left=200,
width=500, height=500,status=1")
}
function init() {
var win = window.open("", "MyWindow", "top=1000,left=300,width=200, height=200")
win.document.write("<h3>Hello World!!!</h3>")
}
function createWindows() {
for (i = 500; i < 750; i += 50) {
var x = i + 100;
var y = i + 100;
var mywin = window.open("", "win" + i, "width=100, height=100,top=" + x + ",left=" + y + "
,status=1")
}
}
</script>
</head>
<body onload="init()">
<h3>Creating a Child window</h3>
<form action="#">
<input type="button" value="Open Window" onclick="openWindow()" />
<input type="button" value="Create Multiple Windows" onclick="createWindows()" />
</form>
<h3>Writing content on Child window</h3>
<script>
var myWindow = open('', 'mywin', 'height=300, width=300');
myWindow.document.write('Hi there.');
myWindow.document.write('This is my new window');
myWindow.document.close();
myWindow.focus();
</script>
Pathan Firozkhan S. 28 Jamia Polytehnic, Akkalkuwa
Diploma in Computer Engg. Java Script Practical (22519)
</body>
</html>
Program Output :
Exp 12 : Develop a web page for validation of form field us regular expression.
<!DOCTYPE html>
<html lang="en">
<head>
<title>Exp 12</title>
<script>
function testexp() {
var patt = /jamia/i;
var str = txt.value;
var res = patt.test(str)
document.getElementById("demo").innerHTML = res;
}
function searchexp() {
var patt = /abc/gmi;
var str = txt1.value;
var res = str.search(patt);
document.getElementById("demo1").innerHTML = res;
}
function matchexp() {
var patt = /abc/g;
var str = txt2.value;
var res = str.match(patt);
document.getElementById("demo2").innerHTML = res;
}
function rangeexp() {
var patt = /[^abc]/;
var str = txt3.value;
var res = patt.test(str);
document.getElementById("demo3").innerHTML = res;
}
function checkmail() {
var patt = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;
var str = txt4.value;
var res = patt.test(str)
if (res == true) {
document.getElementById("demo4").innerHTML = "email address is valid";
} else {
document.getElementById("demo4").innerHTML = "email address is invalid";
Pathan Firozkhan S. 30 Jamia Polytehnic, Akkalkuwa
Diploma in Computer Engg. Java Script Practical (22519)
}
}
function myfun() {
var str = txt5.value;
var res = str.replace("is", "was");
document.getElementById("demo5").innerHTML = res;
}
function mynum() {
var str = txt6.value;
//var patt = /^(?:(?:\+|0{0,2})91(\s*[\-]\s*)?|[0]?)?[789]\d{9}$/;
var patt = "(0/91)?[7-9][0-9]{9}";
if (str.match(patt)) {
document.getElementById("demo6").innerHTML = "Valid Mobile N0."
} else {
document.getElementById("demo6").innerHTML = "Invalid Mobile N0."
}
}
function mypass() {
var str = txt7.value;
var patt = /^(?=.*\d)(?=.*[a-zA-Z])[a-zA-Z0-9]{7,}$/
if (str.match(patt)) {
document.getElementById("demo7").innerHTML = "Valid Password."
} else {
document.getElementById("demo7").innerHTML = "Password must contain more then 8
char, Uppercase, Lowercase, digit and special character";
} }
</script>
</head>
<body>
The test() method to test string contains "jamia" matching patter<br>
Enter any text : <input type="text" id="txt">
<input type="button" onclick="testexp()" value="Check"><br>
The string contains patter : <span id="demo"></span><br><br>
Program Output :
Program Output :
<td>
<img height="1" src="" width="10">
</td>
<td>
<a onmouseover="OpenNewWindow(1)" onmouseout="MyWindow.close()">
<b><u>Java Demystified </u></b>
</a>
<br>
<a onmouseover="OpenNewWindow(2)" onmouseout="MyWindow.close()">
<b><u>OOP Demystified</u></b>
</a>
<br>
<a onmouseover="OpenNewWindow(3)" onmouseout="MyWindow.close()">
<b><u>Data Structures Demystified</u></b>
</a>
</td>
</tr>
</tbody>
</table></body></html>
Program Output :
<select name="employees">
<option value="0">Employees</option>
</select>
<br>
<input type="submit" value="Submit">
<input type="reset" value="Reset">
</form>
</body></html>
Program Output :
display: none;
}
.active {
display: block;
}
</style>
</head>
<body>
<h2>Tree View Menu</h2>
<p>A tree view represents a hierarchical view of information,<br> where each item can have a
number of subitems.</p>
<p>Click on the arrow(s) to open or close the tree branches.</p>
<ul id="myUL">
<li><span class="caret">Beverages</span>
<ul class="nested">
<li>Water</li>
<li>Coffee</li>
<li><span class="caret">Tea</span>
<ul class="nested">
<li>Black Tea</li>
<li>White Tea</li>
<li><span class="caret">Green Tea</span>
<ul class="nested">
<li>Sencha</li>
<li>Gyokuro</li>
<li>Matcha</li>
<li>Pi Lo Chun</li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
</ul>
<script>
var toggler = document.getElementsByClassName("caret");
var i;
for (i = 0; i < toggler.length; i++) {
Pathan Firozkhan S. 42 Jamia Polytehnic, Akkalkuwa
Diploma in Computer Engg. Java Script Practical (22519)
toggler[i].addEventListener("click", function() {
this.parentElement.querySelector(".nested").classList.toggle("active");
this.classList.toggle("caret-down");
});
}
</script>
</body>
</html>
Program Output :
Exp 15 : Develop a webpage for implementing status bar and web page protection
<!DOCTYPE html>
<html lang="en">
<head>
<title>Exp 15</title>
<script>
msg = "This is an example of scrolling message";
spacer = "............ .............";
pos = 0;
function ScrollMessage() {
window.status = msg.substring(pos, msg.length) + spacer + msg.substring(0, pos);
pos++;
if (pos > msg.length)
pos = 0;
window.setTimeout("ScrollMessage()", 100);
}
</script>
<script>
window.onload = function() {
document.addEventListener("contextmenu", function(e) {
e.preventDefault();
}, false);
}
</script>
</head>
<body onfocus="window.status = 'Welcome to Java Script!'; return true">
<h3>Right click is disabled, for protecting webpage source code</h3>
<p>Scrolling Message<br>
<input type="button" value="click Me" onclick="ScrollMessage()">
Look at the status line at the bottom of the page</p>
<p>Changing the message using Rollover<br>
<input type="button" name="btn" value="Click Me" onMouseOver="window.status='Mouse
cursor in on Button';return true" onMouseOut="window.status='Mouse cursor in not on Button';return
true"></p>
</body>
</html>
Program Output :
Program Output :
Best of Luck
Pathan Firozkhan S. 48 Jamia Polytehnic, Akkalkuwa