0% found this document useful (0 votes)
3 views8 pages

Javascript 2

The document provides various examples of JavaScript functionalities, including form validation for name and password, event handlers for click, mouseover, keydown, focus, and load events. Each section includes HTML forms and corresponding JavaScript functions to demonstrate how to validate inputs and handle user interactions. The examples illustrate basic JavaScript syntax and event handling techniques for web development.

Uploaded by

elnini8412
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)
3 views8 pages

Javascript 2

The document provides various examples of JavaScript functionalities, including form validation for name and password, event handlers for click, mouseover, keydown, focus, and load events. Each section includes HTML forms and corresponding JavaScript functions to demonstrate how to validate inputs and handle user interactions. The examples illustrate basic JavaScript syntax and event handling techniques for web development.

Uploaded by

elnini8412
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/ 8

JavaScript in Action II

JavaScript: Form validation


<script> }
function validateform(){ </script>
var name=document.myform.name.value; <body>
var <form name="myform" method="post"
password=document.myform.password.value; action="abc.jsp" onsubmit="return
if (name==null || name==""){ validateform()" >
alert("Name can't be blank"); Name: <input type="text"
name="name"><br/>
return false;
Password: <input type="password"
}else if(password.length<6){ name="password"><br/>
alert("Password must be at least 6 characters <input type="submit" value="register">
long.");
</form>
return false; }
JavaScript: Password validation
<script type="text/javascript">
function matchpass(){
Var firstpassword=document.f1.password.value;
var secondpassword=document.f1.password2.value;
if(firstpassword==secondpassword){
return true; } <form name="f1" action="register.jsp" onsubmit="return
else{ matchpass()">
alert("password must be same!"); Password:<input type="password" name="password"
/><br/>
return false; } }
Re-enter Password:<input type="password"
</script> name="password2"/><br/>
<input type="submit">
</form>
JavaScript: Event Handler – click event
<html> </script>
<head> Javascript Events </head> <form>
<body> <input type="button" onclick="clickevent()"
<script language="Javascript" value="Who's this?"/>
type="text/Javascript"> </form>
<!-- </body>
function clickevent() </html>
{
document.write("This is FSKM");
}
//-->
JavaScript: Event Handler – MouseOver event
<html> <!--
<head> function mouseoverevent()
<h1> Javascript Events </h1> {
</head> alert("This is FSKM");
<body> }
<script language="Javascript" //-->
type="text/Javascript"> </script>
<p onmouseover="mouseoverevent()"> Keep
cursor over me</p>
</body>
</html>
JavaScript: Event Handler – Keydown event
<html>
<head> Javascript Events</head>
<body>
<h2> Enter something here</h2>
<input type="text" id="input1" onkeydown="keydownevent()"/>
<script>
<!-- function keydownevent()
{ document.getElementById("input1");
alert("Pressed a key"); }
//-->
</script>
</body>
</html>
JavaScript: Event Handler – Focus event
<html>
<head> Javascript Events</head>
<body>
<h2> Enter something here</h2>
<input type="text" id="input1" onfocus="focusevent()"/>
<script>
<!-- function focusevent()
{
document.getElementById("input1").style.background=" aqua";
} //-->
</script>
</body>
</html>
JavaScript: Event Handler – Load event
<html>
<head>Javascript Events</head>
</br>
<body onload="window.alert('Page successfully loaded');">
<script>
<!--
document.write("The page is loaded successfully");
//-->
</script>
</body>
</html>

You might also like