Welcome to Scribd. Sign in or start your free trial to enjoy unlimited e-books, audiobooks & documents.Find out more
Standard view
Full view
of .
Look up keyword
Like this
0 of .
Results for:
No results containing your search query
P. 1
Lecture 44

Lecture 44

Ratings: (0)|Views: 82|Likes:
Published by api-3729920

More info:

Published by: api-3729920 on Oct 15, 2008
Copyright:Attribution Non-commercial


Read on Scribd mobile: iPhone, iPad and Android.
download as PDF, TXT or read online from Scribd
See more
See less





Handout 44
Web Design & Development
Umair\u00a9 2006, All Rights Reserved
- 1-
Lecture 44

Client Side Validation
JavaServer Faces (JSF)

In this handout, we\u2019ll talk about client side validation and also learn about growing in
demand Java technology i.e. JSF. First start with client side validation
Client Side Validation

Forms validation on the client-side is essential -- it saves time and bandwidth, and gives you more options to point out to the user where they've gone wrong in filling out the form. Furthermore, the browser doesn't have to make a round-trip to the server to perform routine client-side tasks. For example, you wouldn't want to send the browser to the server to validate that all of the required fields on a form were filled out.

Any scripting language can be used to achieve the said objective. However,Ja vaSc rip t
andVBScript are two popular options
Why is Client Side Validation Good?
There are two good reasons to use client-side validation:
It's a fast form of validation: if something's wrong, the alarm is triggered upon
submission of the form.
You can safely display only one error at a time and focus on the wrong field, to
help ensure that the user correctly fills in all the details you need.
Code Example: Form Validation using JavaScript

For example on the following form, we want to make sure that text filed for name should not be left empty and age field does not contain any negative value. To accomplish this we\u2019ll use JavaScript.

If user forgets to provide name and/or enters a negative value, a message would be displayed to the user that indicates what was went wrong? However, if user conforms to requirements, he/she would be taken to another page that displays a greeting message.

Note:In this example, JavaScript semantics isn\u2019t discussed over here as I am assuming
that you might be familiar with some scripting language. Otherwise,
www.w3schools.com is an excellent resource to learn about scripting languages
Handout 44
Web Design & Development
Umair\u00a9 2006, All Rights Reserved
- 2-
The code that is used to generate this page is given below:
<!\u2014 start of scripting code and mentioning type -->
<SCRIPT TYPE = "text/javascript">
<!\u2014 defining a function that receives form\u2019s reference, defined
inside the body and returns false if any requirement violated
-->function validateForm(thisform)
<!\u2014 checking the value of the name field, if it is left empty
then displaying a message
if (thisform.name.value == null || thisform.name.value == "")

alert("Username is required");
return false;

<!\u2014 if value of age is negative, displaying a message -->
if (thisform.age.value < 0 )

alert("Age can't be negative");
return false;

} // end of function
</SCRIPT> <!\u2014end of script-- >
Handout 44
Web Design & Development
Umair\u00a9 2006, All Rights Reserved
- 3-

<!\u2014 validateForm method is called and specified as a value of
onsubmit value, if this method returns false, the user remains
on the same page

<FORM method="post" onsubmit="return validateForm(this)"
action = \u201cgreeting.jsp\u201d >
<h2> Client Side Validation Example </h2>
Name: <INPUT type="text"name ="na me" size="30" />
<BR/> <BR/>
Age: <INPUT type="text"name="age" size="30" />
<BR/> <BR/>
<INPUT type="submit" value="Submit">

Activity (5)

You've already reviewed this. Edit your review.
1 hundred reads
ALi liked this
ALi liked this
Omer Ali liked this
smrsaxena liked this

You're Reading a Free Preview

/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->