Javascript: Targeted At: Entry Level Trainees
Javascript: Targeted At: Entry Level Trainees
2
Icons Used
Hands on
Questions Tools Exercise
A Welcome
Try it Out Contacts
Break
3
JavaScript Session 04 Demo: Overview
Introduction:
This demo demonstrates about Java Scrip pre-defined
functions and objects, JavaScript events, and different
types of message boxes.
4
JavaScript Session 04 Demo: Objective
Objective:
After completing this session, you will be able to:
» Define Java Scrip pre-defined functions and objects
» Describe JavaScript events
» List different types of message boxes
5
Demo
Problem Statement:
6
Demo (Contd.)
Code:
<label>Date of Birth:*</label>
<fieldset id='dateOfBirth'>
<input name="dobMonth" maxlength="2" size="2" value="MM"
onfocus="if(this.value=='MM')this.value='';" class="dom"
id="dobMonth" alt=" " type="text"
onBlur="validatemonth(dobMonth); validatedigit();"/>
<input name="dobDay" maxlength="2" size="2" value="DD"
onfocus="if(this.value=='DD')this.value='';" class=" dod"
id="dobDay" alt=" " type="text" onBlur=" validateday(dobDay);
validatedigit();"/>
<input name="tmpDobYear" maxlength="4" size="4" value="YYYY"
onfocus="if(this.value=='YYYY')this.value='';" class=" doy"
id="tmpDobYear" alt=" " type="text" onBlur="validateyear();
validatedigit();"/>
</fieldset><br>
Refer File Name: Code Dump_SEC_04_Demo.txt for soft copy of the code
7
Demo (Contd.)
function validateyear(){
var month=parseFloat(dobMonth.value);
if(month==2){
var limit=28;
if(tmpDobYear.value% 400==0 || (tmpDobYear % 100 !=0 &&
(tmpDobYear%4==0))){
limit=29;
}
if(dobDay.value>limit){
alert(“ Day cant exceed 29 for this month“);
}
else{
document.getElementById('seventhdiv').innerHTML=" ";
}
}
var cur_date = new Date();
var cur_month = cur_date.getMonth();
var cur_day = cur_date.getDate();
var cur_year =cur_date.getYear();
Refer File Name: Code Dump_SEC_04_Demo.txt for soft copy of the code
8
Demo (Contd.)
How it Works:
The validateyear() method in the HTML for
the Date field set calls the validateyear()
method in the validate.js file.
In that var
month=parseFloat(dobMonth.value); is a
pre-defined function which parses the month
value that we enter and trims any leading
white spaces and gives only the float value
that we entered.
9
Demo (Contd.)
10
Q&A
11
JavaScript Session 04 Demo:
Source
Cognizant Project List Maintenance System
Disclaimer: Parts of the content of this course is based on the materials available from the Web sites and
books listed above. The materials that can be accessed from linked sites are not maintained by
Cognizant Academy and we are not responsible for the contents thereof. All trademarks, service marks,
and trade names in this course are the marks of the respective owner(s).
12
You have completed the
Session 04 Demo of
JavaScript.