Data Validation: Dodda - Venkata Reddy
Data Validation: Dodda - Venkata Reddy
1. Data validation
Validation is a simple process ensuring some data might be correct for a particular application. Broadly speaking
data validation is a process of ensuring that users submit only the set of characters which you require. It is the
process of ensuring that the data is in any way accurate.
Example1:
One common request is for a way validating email address. We can validate the email by the help of JavaScript.
There are many criteria that need to be following to validate the email id such as:
Email id must contain the @ and . character
There must be at least one character before and after the @.
There must be at least two characters after . (dot).
In this example, we are going to validate the name and password. The name can’t be empty and password can’t
be less than 6 characters long.
Here, we are validating the form on form submit. The user will not be forwarded to the next page until given
values are correct.
<html>
<body>
<script>
function validateform(){
var name=document.myform.name.value;
var password=document.myform.password.value;
if (name==null || name==""){
alert("Name can't be blank");
return false;
}else if(password.length<6){
alert("Password must be at least 6 characters long.");
return false;
}
}
</script>
<body>
<form name="myform" method="post" action="http://www.javatpoint.com/javascriptpages/valid.jsp"
onsubmit="return validateform()" >
Name: <input type="text" name="name"><br/>
Password: <input type="password" name="password"><br/>
<input type="submit" value="register">
</form>
</body>
</html>
A new window can be open which contains a URL identified resources and the attributes of that window can be
tailored to suit the application.
To open a new window we usually resort to certain predefined JavaScript functions. Following is the syntax in
this regard.
URL: Here we supply the web address of the page that we wish to be displayed in our window.
Window Name: Here a name can be given to the window.
Attributes: These are various attributes defined for a given window. Such as width, height, scrollbars, status,
menu bar ext…
<!DOCTYPE html>
<html>
<head>
<title>window open and close method</title>
<script>
var Window;
// Function that open the new Window
function windowOpen()
{
Window = window.open("https://www.geeksforgeeks.org/", "_blank", "width=400, height=450");
}
// function that Closes the open Window
function windowClose()
{
Window.close();
}
</script> </head>
<body>
<button onclick="windowOpen()">Open GeeksforGeeks</button>
<button onclick="windowClose()">Close GeeksforGeeks</button>
2. prompt(text, defaultText)
The prompt() method displays a dialog box that prompts the visitor for input. A prompt box is often used if you
want the user to input a value before entering a page.
3. alert(message)
The alert() method displays an alert box with a specified message and an OK button. An alert box is often used if
you want to make sure information comes through to the user.
<html>
<head>
<script language="javascript">
<!--
function Init(){
self.status = "Some Message";
}
//-->
One single window can be occupied by multiple frames and also the way elements of one frame can be used to
manipulate elements of other frames etc. is show in following example.
1. The frameset
The whole page is built around a simple frameset. When the page is initially loaded, It displays the form in the
lower window and empty window and an empty HTML page in the upper Window.
Frame.html
<html>
<head>
<title> program to introduce frames</title>
<form>
<frameset rows=”50%, 50%”>
<frame src=”frame1.html name=”fd1”>
<frame src=”frame2.html name=”fd2”>
</frameset>
</form>
<body>
</body>
</html>
frame1.html
<html>
<head>
<title> Frame One</title>
frame2.html
<html>
<head>
<title>frame 2</title>
</head>
<body>
<h1> this is frame2 </h1>
</body>
<form>
<input type=”button” value=”display” onClick=parent.fd1.display()”>
</form>
</body>
</html>
6. Rollover Buttons
What is an Image Rollover?
An image rollover occurs when a graphic is moused over (no clicking is involved) and that graphic is
replaced by another graphic.
This is typically done for navigation buttons.
If just the navigation button changes, it is referred to as a single rollover. If the button changes and
another graphic elsewhere on the page also changes, it is referred to as a multiple rollover.
JavaScript is commonly used to create these rollover effects, using the onmouseover event handler to
trigger the rollover graphic and the onmouseout event handler to return the graphic to its original state.
<!DOCTYPE html>
<html>
<body>
<img onmouseover="bigImg(this)" onmouseout="normalImg(this)" border="0" src="smiley.gif" alt="Smiley"
width="32" height="32">
<p>Roll Over Buttons </p>
<script>
function bigImg(x) {
x.style.height = "64px";
x.style.width = "64px";
}
7. Moving Images
The moving images is the actually is a layer of content. Images (Layers) can move around reputedly but doing so
takes up processor cycles. If our images only move for a restricted amount of time such as when the page is first
loaded or when the user specifically triggers the event. Each layer can be positioned on the screen by changing
the offset of the top left corner of the layer.
Example
<!DOCTYPE html>
<html>
<style>
#myContainer {
width: 400px;
height: 400px;
position: relative;
background: yellow;
}
#myAnimation {
width: 50px;
height: 50px;
position: absolute;
background-color: red;
}
</style>
<body>
<p>
function myMove() {
var elem = document.getElementById("myAnimation");
var pos = 0;
var id = setInterval(frame, 10);
function frame() {
if (pos == 350) {
clearInterval(id);
} else {
pos++;
elem.style.top = pos + 'px';
elem.style.left = pos + 'px';
}
}
}
</script>
</body>
</html>
Example:
<html>
<head>
<script language=”JavaScript”>
function one()
{
con1.style.visibility=”hidden”;
}
function two()
{
con2.style.visibility=”visible”;
}
function three()
{
con2.style.visibility=”hidden”;
con3.style.visibility=”visible”;
}
</script>
</head>
<body>
<p>
<a href=”#” onClick=one()>one</a>
<a href=”#” onClick=two()>one</a>
<a href=”#” onClick=three()>one</a>
</p>
<div id=:con1” style=”visibility:visible”>
Example:
<html>
<head>
<link rel=”style sheet” href=”./style.css”>
<script language=”JavaScript” src=”./menu.js”>
</script>
</head>
<body>