0% found this document useful (0 votes)
46 views9 pages

Noormst 4

The document contains 5 JavaScript programs: 1. Displays an alert with "Hello world, welcome to JavaScript" when the page loads. 2. Displays an alert with "Thanks for visiting our website" when the page unloads. 3. Changes the content of a div from "welcome to HTML" to "welcome to JavaScript" when a button is clicked. 4. Prints the username and password entered in a form along with their lengths when submitted. 5. Checks username and password fields for empty/invalid values and displays appropriate messages. If valid, welcomes the user.

Uploaded by

noorullahmd461
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
46 views9 pages

Noormst 4

The document contains 5 JavaScript programs: 1. Displays an alert with "Hello world, welcome to JavaScript" when the page loads. 2. Displays an alert with "Thanks for visiting our website" when the page unloads. 3. Changes the content of a div from "welcome to HTML" to "welcome to JavaScript" when a button is clicked. 4. Prints the username and password entered in a form along with their lengths when submitted. 5. Checks username and password fields for empty/invalid values and displays appropriate messages. If valid, welcomes the user.

Uploaded by

noorullahmd461
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

MST-LAB PSCMR COLLEGE OF ENGINEERING AND TECHNOLOGY

WEEK – 4A
AIM: 1) write a java script program to print hello world,welcome to java script while the page is being
loaded
Source Code:
<html>
<head>
<script>
function welcome()
{
alert("Hello world,welcome to java script")
}
</script>
</head>
<body onload="welcome();">
</body>
</html>
Output:

SUBMITTED BY: 20KT1A4229 PAGE NO :_____


MST-LAB PSCMR COLLEGE OF ENGINEERING AND TECHNOLOGY

2)write a java scriptprogram to display thanks for visiting our website while living the page

Code:
<html>
<head>
<script>
function welcome()
{
alert("Thanks for visiting our website");
}
</script>
</head>
<body onunload="welcome();">
</body>
</html>

SUBMITTED BY: 20KT1A4229 PAGE NO :_____


MST-LAB PSCMR COLLEGE OF ENGINEERING AND TECHNOLOGY

3) write a java script program to change the content of a particular block when a user clicks on the click
me button..the block should initially consists of HTML later it should be converted as welcome to java
script
Code:
<html>
<head>
<script>
function whenclick()
{
var data="welcome to java script";
document.getElementById("id1").innerHTML=data;
}
</script>
</head>
</body>
<div id="id1">
welcome to html
</div><br>
<button onclick="whenclick();">click me</button>
</body>
</html>
Output:

Fig 1: output for onclick handler module-1

Fig 2: output for onclick handler module-2

SUBMITTED BY: 20KT1A4229 PAGE NO :_____


MST-LAB PSCMR COLLEGE OF ENGINEERING AND TECHNOLOGY

4) write a java script program to print the username and password when a user submit the login page
Code:
<html>
<head>
<script>
function user(){
var uname=document.getElementById("uname").value;
var pass=document.getElementById("pass").value;
document.writeln("username:"+uname);
document.writeln("password:"+pass);
document.writeln("username length:"+uname.length);
document.writeln("password length:"+pass.length);
}
</script>
</head>
<body>
<form onsubmit="user();">
username:<input type="text" id="uname"><br>
password:<input type="password" id="pass"><br>
<input type="submit">
</form>
</body>
</html>
Output:

Fig 1: output for on submit handler module-1

Fig 2: output for on submit handler module-2

SUBMITTED BY: 20KT1A4229 PAGE NO :_____


MST-LAB PSCMR COLLEGE OF ENGINEERING AND TECHNOLOGY

5) write a javascript program to check the username and password with given conditions.
a)username cannot be null
b)password cannot be null
c)password should be greater than 8characters and cannot be less than 4 characters
d)if the username and password are not equal please post a error message in a special window saying
that invalid username or password
e)if the username and password are equal display hi,username welcome to our website

code:
<html>
<head>
<script>
function c()
{
var un=document.getElementById('uname').value;
var pwd=document.getElementById('pwd').value;
var pwdlen=pwd.length;
if(un=="")
{
if(pwd=="")
{
alert("Enter User name and password");
}
else
{
alert("Enter valid username");
}
}
else if(un!="")
{
if(pwdlen>8)
{
if(un==pwd)
{
document.writeln("Hello"+un );
document.writeln("Welcome to our website");

}
else
{
alert("Invalid user name or password");
}

SUBMITTED BY: 20KT1A4229 PAGE NO :_____


MST-LAB PSCMR COLLEGE OF ENGINEERING AND TECHNOLOGY

}
}
</script>
</head>
<body>
<form>
User name:<input type="text" id="uname"><br>
password:<input type="password" id="pwd"><br>
<button onclick="c();">Submit</button>
</form>
</body>
</html>
Output:

Fig 1:output for empty username and password

Fig 2: output for empty username

SUBMITTED BY: 20KT1A4229 PAGE NO :_____


MST-LAB PSCMR COLLEGE OF ENGINEERING AND TECHNOLOGY

Fig 3: output for password not equal to username

Fig 4: output for on submit handler module-1

Fig 5: output for on submit handler module-2

SUBMITTED BY: 20KT1A4229 PAGE NO :_____


MST-LAB PSCMR COLLEGE OF ENGINEERING AND TECHNOLOGY

WEEK-4B
AIM: Write a java script program which display welcome to pscmr and it allows variables using
var.Let apply all the string operations and every new string which is obtained after operation should be
in separate block.
Code:
<html>
<head>
</head>
<body>
<div id="a">Welcome to pscmr</div>
<div id="z">welcome to college,welcome to csm </div>
<div id="b">
</div>
<div id="c"></div>
<div id="d"></div>
<div id="e"></div>
<div id="f"></div>
<div id="g"></div>
<div id="h"></div>
<div id="i"></div>
<div id="j"></div>
<div id="k"></div>
<div id="l"></div>
<div id="m"></div>
<script>
var a=document.getElementById("a").innerHTML;
var b=document.getElementById("b");
b.innerHTML="Upper case string is: "+a.toUpperCase();
var c=document.getElementById("c");
c.innerHTML="Lower case string is: "+a.toLowerCase();
var d=document.getElementById("d");
d.innerHTML = "Slicing: " + a.slice(3, 7);
document.getElementById("e").innerHTML="Substring is: "+a.substring(-3,7);
document.getElementById("f").innerHTML="Substr is: "+a.substr(1,7);
document.getElementById("g").innerHTML="Replace is: "+a.replace("pscmr","PSCMR");
document.getElementById("h").innerHTML="Match is: "+a.match("pscmr");
var z=document.getElementById("z").innerText;
document.getElementById("i").innerHTML="Replaceall is: "+z.replaceAll("welcome","hello");
document.getElementById("j").innerHTML="Index is: "+a.indexOf("to");
document.getElementById("j").innerHTML="Index is: "+z.indexOf("to");
document.getElementById("k").innerHTML="LastIndex is: "+z.lastIndexOf("to");
document.getElementById("l").innerHTML="Concat is: "+a.concat(z);
SUBMITTED BY: 20KT1A4229 PAGE NO :_____
MST-LAB PSCMR COLLEGE OF ENGINEERING AND TECHNOLOGY

document.getElementById("m").innerHTML="split is: "+z.split(",");


</script>
</body>
</html>
Output:

SUBMITTED BY: 20KT1A4229 PAGE NO :_____

You might also like