Noormst 4
Noormst 4
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:
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>
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:
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:
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");
}
}
}
</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:
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