Javascript Lab Manual

download Javascript Lab Manual

of 33

Transcript of Javascript Lab Manual

Aim: To study And Implement Javascript in Html

A scripting language is a form of programming language that is usually interpreted rather than compiled. Conventional programs are converted permanently into executable files before they are run. In contrast, programs in scripting language are interpreted one command at a time. Scripting languages are often written to facilitate enhanced features ofWeb sites. These features are processed on the server but the script in a specific page runs on the user's browser. In most cases, it is easier to write the code in a scripting language than in a compiled language. However, scripting languages are slower because the instructions are not handled solely by the basic instruction processor. Scripting languages allow rapid development and can communicate easily with programs written in other languages. Scripting languages can be used to create specialized GUIs (graphical user interfaces) and forms that enhance the convenience of search engines, Web-based e-mail and e-commerce. Many Web sites require that the user's browser be set to run scripts to take advantage of all the features of the site. In some cases, Web sites are practically useless unless the user's computer is set to run programs locally in a scripting language.

bash Bourne shell C shell ECMAScript JavaScript JScript LotusScript Perl PHP Python

Types of Scripting Client Side Server Side

Client Side Scripting:Client-side scripting generally refers to the class of computer programs on the web that are executed client-side, by the user's web browser, instead of server-side (on [1] the web server). This type ofcomputer programming is an important part of the Dynamic HTML (DHTML) concept, enabling web pages to be scripted; that is, to have different and changing content depending on user input, environmental conditions (such as the time of day), or other variables. Client-side scripts are often embedded within an HTML or XHTML document (hence known as an "embedded script"), but they may also be contained in a separate file, which is referenced by the document (or documents) that use it (hence known as an "external script"). Upon request, the necessary files are sent to the user's computer by the web server (or servers) on which they reside. The user's web browser executes the script, then displays the document, including any visible output from the script. Client-side scripts may also contain instructions for the browser to follow in response to certain user actions, (e.g., clicking a button). Often, these instructions can be followed without further communication with the server. By viewing the file that contains the script, users may be able to see its source code. Client-side scripts have greater access to the information and functions available on the user's browser, whereas server-side scripts have greater access to the information and functions available on the server

Server Side Scripting:server-side scripts, written in languages such as Perl, PHP, ASP.NET, Java, and server-side VBScript, are executed by the web server when the user requests a document. They produce output in a format understandable by web browsers (usually HTML), which is then sent to the user's computer. The user cannot see the script's source code (unless the author publishes the code separately), and may not even be aware that a script was executed. Documents produced by server-side scripts may, in turn, contain client-side scripts. Server-side scripts require that their language's interpreter be installed on the server, and produce the same output regardless of the client's browser, operating system, or other system details.

Java Script:It is a prototype-based scripting language that is dynamic, weakly typed and has first[5] class functions. It is a multi-paradigm language, supporting object-oriented, imperative, [1][6] and functional programming styles. JavaScript was designed to add interactivity to HTML pages JavaScript is a scripting language A scripting language is a lightweight programming language JavaScript is usually embedded directly into HTML pages JavaScript is an interpreted language (means that scripts execute without preliminary compilation)

Features: Imperative and structuredJavaScript supports much of the structured programming syntax from C (e.g., if statements, while loops, switch statements, etc.). One partial exception is scoping: C-style block-level scoping is not supported (instead, JavaScript has function-level scoping). JavaScript 1.7, however, supports block-level scoping with the let keyword. Like C, JavaScript makes a distinction between expressionsand statements. One syntactic difference from C is automatic semicolon insertion, in which the semicolons that terminate statements can be [21] omitted.

DynamicAs in most scripting languages, types are associated with values, not with variables. For example, a variable x could be bound to a number, then later rebound to a string. JavaScript supports various ways to test the type of an object, including duck typing.

Object basedJavaScript is almost entirely object-based. JavaScript objects are associative arrays, augmented with prototypes (see below). Object property names are string keys: obj.x = 10 andobj['x'] = 10 are equivalent. Properties and their values can be added, changed, or deleted at run-time. Most properties of an object (and those on its prototype inheritance chain) can be enumerated using a for...in loop. JavaScript has a small number of built-in objects such as Function and Date.

A sample HTML embedded javascript simple page This is JavaScript document.write('Hello World!'); var h1 = document.getElementById("header"); // holds a reference to the tag h1 = document.getElementByTagName("h1")[0]; // accessing the same element Your browser either does not support JavaScript, or has JavaScript turned off.

A sample User Registration Form using javascript and Html User Registration Form

function verify(form) { if(document.forms[0].elements[0].value=="") { alert("Please Enter User ID"); document.forms[0].elements[0].focus(); return(false); } if(document.forms[0].elements[1].value=="") { alert("Please Enter your Password"); document.forms[0].elements[2].value=""; document.forms[0].elements[1].focus(); return(false); } if(document.forms[0].elements[1].value.length { if(document.forms[0].elements[11].value=="") { alert("Please Enter your First Name"); document.forms[0].elements[11].focus(); return(false); } if(document.forms[0].elements[13].value=="") { alert("Please Enter your Last Name"); document.forms[0].elements[13].focus(); return(false); } if(document.forms[0].elements[14].value=="Year") { alert("Please specify your Academic year"); document.forms[0].elements[14].focus(); return(false); }

if(document.forms[0].elements[15].value=="adminyear") { alert("Please put your Admission Year"); document.forms[0].elements[15].focus(); return(false); }

if(document.forms[0].elements[16].value=="dept") { alert("Please Select your Department"); document.forms[0].elements[16].focus(); return(false); }

if(document.forms[0].elements[17].value=="") { alert("Please put your Roll Number"); document.forms[0].elements[17].focus(); return(false); }

if(document.forms[0].elements[17].value!="") { r0=document.forms[0].elements[17].value.indexOf('2'); r1=document.forms[0].elements[17].value.indexOf('k'); r2=parseInt(document.forms[0].elements[17].value.charAt(2)); r3=document.forms[0].elements[17].value.indexOf('_'); r4=parseInt(document.forms[0].elements[17].value.charAt(4)); r5=parseInt(document.forms[0].elements[17].value.charAt(5)); r6=parseInt(document.forms[0].elements[17].value.charAt(6));

len=document.forms[0].elements[17].value.length;

if((len!=7)||(r0!=0)||(r1!=1)||(r3!=3)||(r4>6 || r49 || r2

switch(document.forms[0].elements[14].value) { case 'Fourth': if(r2!=1||(r2>9||r29||r29||r29||r2

if(document.forms[0].elements[17].value!="selecthostel") {

if((document.forms[0].elements[8].checked==true)&&(document.forms[0].elements[18].value=="LH")) { alert("You are Male user::Please select Boys Hostel"); document.forms[0].elements[18].focus(); return(false); }

if((document.forms[0].elements[9].checked==true)&&(document.forms[0].elements[18].value!="LH")) { alert("You are Female user::Please select L.H."); document.forms[0].elements[18].focus(); return(false); }

}

}

if(document.forms[0].elements[24].checked==true) { if(document.forms[0].elements[25].value=="") { alert("Please Enter Your First Name"); document.forms[0].elements[25].focus(); return(false); } if(document.forms[0].elements[27].value=="") { alert("Please Enter your Last Name");

document.forms[0].elements[27].focus(); return(false); } if(document.forms[0].elements[30].value=="state") { alert("Please Select Your State"); document.forms[0].elements[30].focus(); return(false); } if(document.forms[0].elements[31].value=="country") { alert("Please Select Your State"); document.forms[0].elements[31].focus(); return(false); }

if((document.forms[0].elements[32].value=="pincode")||(document.forms[0].elements[33].value="")) { alert("Please Select Your Pincode OR if Other specify"); document.forms[0].elements[32].focus(); return(false); }

}

}

function studentclear(form) { document.forms[0].elements[11].value="";

document.forms[0].elements[12].value=""; document.forms[0].elements[13].value=""; document.forms[0].elements[14].value="Year"; document.forms[0].elements[15].value="adminyear"; document.forms[0].elements[16].value="dept"; document.forms[0].elements[17].value=""; document.forms[0].elements[18].value="selecthostel"; document.forms[0].elements[19].value=""; document.forms[0].elements[20].value=""; document.forms[0].elements[21].value=""; document.forms[0].elements[22].value=""; document.forms[0].elements[23].value=""; document.forms[0].elements[25].focus(); } function generalclear(form) { document.forms[0].elements[25].value=""; document.forms[0].elements[26].value=""; document.forms[0].elements[27].value=""; document.forms[0].elements[28].value="City"; document.forms[0].elements[29].value=""; document.forms[0].elements[30].value="state"; document.forms[0].elements[31].value="country"; document.forms[0].elements[32].value="pincode"; document.forms[0].elements[33].value=""; document.forms[0].elements[34].value=""; document.forms[0].elements[35].value=""; document.forms[0].elements[36].value=""; document.forms[0].elements[37].value=""; document.forms[0].elements[11].focus(); }

New User Registration Form

*

Indicates all the fields are mandatory *

User ID: (Contains only letters (a-z), numbers (0-9) and underscore)

*

Password:

(Password should be of minimum 4(four) and maximum 10(ten) characters.) *Re-Type

Password: If you forget your password, you can retrieve it by answering your unique hint question.
Frame your question such that only you know its answer.


*Select a question forgetting password : Select a hit question

? What is your favourite multimedia software?

What is your favourite game? who is your favourite Cricketer? who is your favourite Film Actor? what is your favourite food?

*Hit

Answer:

(Write

Your Answer)

DD

MM YYYY

*Date of Birth:

Day 1 2

3 4 5 6 7 8

9 10 11 12 13 14

15 16 17 18 19 20

21 22 23 24 25 26

27 28 29

30 31

Month JAN FEB MAR APR

MAY JUN JUL AUG SEP OCT

NOV DEC Year

2006

2007 2008 2009 2010 2011 2012

2013 2014 2015 2016 2017 2018

2019 2020

*Gender : Male Female

Student

First Name: Middle Name:

Last Name: Academic Year:

Year First Second Third Fourth

Year of Admission:15 Select Year 2006 2007 2008

2009 2010

Department: Select Department

Information Technology Computer Sc. & Engineering Electronics & Communication Electrical Engineering Mechanical Engineering

Civil Engineering Roll: &nb sp; (Eg.2k1_612::Here 2k1 stands for year 2001:: 1,2,3,4,5,6 for dept Civil,Elect,Mech,Comp,Ece and IT::Left digits indicates roll no)

Hostel No: Select Hostel Hostel 1 Hostel 2 Hostel 3

Hostel 4 Ladies Hostel Room No :

Contact No: - Mobile No:

Email:

General First

Name: Middle Name:

Last Name: Select City: City

Other : (If other city please specify)

Select

State: State ANDRA PRADESH

BIHAR DELHI

JAMMU & KASHMIR HARIYANA KERAL MADHYA PRADESH MAHARASTA

ORRISSA RAJASTAN UTTAR PRADESH WEST BENGAL

Select a Country : Country

Zip Code:

Pincode

Other: (If other Zip please specify)

Contact No: Mobile No:

Email:

The User Registration Form is Shown Below:

Conclusion: Thus We have studied the implementation of javascript in html