Web Page Programming with HTML,DHTML & JavaScript/Session 10/ 6 of 18
Command Button object(2)
Web Page Programming with HTML,DHTML & JavaScript/Session 10/ 7 of 18
Checkbox Object (1)
A Checkbox is an HTML form object that behaves as a toggle switch Checkbox can have either checked or unchecked Like button checkbox also understands onClick event Web Page Programming with HTML,DHTML &
JavaScript/Session 10/ 8 of 18
Checkbox Object(2)
Web Page Programming with HTML,DHTML & JavaScript/Session 10/ 9 of 18
Option Button/Radio Button object(1)
Radio buttons are almost exactly like checkboxes with respect to JavaScript Radio buttons are different. Once a radio button is on, it stays on until another one is selected. Then the first one goes off. Option or radio button also understands onClick event.
Web Page Programming with HTML,DHTML & JavaScript/Session 10/ 10 of 18
Option Button/Radio Button object(1)
Web Page Programming with HTML,DHTML & JavaScript/Session 10/ 11 of 18
ComboBox/Select object(1)
A ComboBox object on an HTML form appears as drop-down list or a scrollable list of selectable items To conserve form space, the scrollable list of selectable items is used ComboBox supports onBlur, onFocus, and onChange events Web Page Programming with HTML,DHTML & JavaScript/Session 10/ 12 of 18
ComboBox/Select object(2)
Web Page Programming with HTML,DHTML & JavaScript/Session 10/ 13 of 18
Form Validation(1)
Validate each and every important field by ensuring that none of the fields are empty. Also the fields should not contain any invalid information. Consider an example: <HTML> <HEAD> <TITLE> Form Events </TITLE> <SCRIPT LANGUAGE="JavaScript">
Page Programming with HTML,DHTML & JavaScript/Session 10/ 14 of 18
Form Validation(2)
function validateFirstName() { var str= form1.fname.value; if(str.length==0) { alert(" The first name cannot be empty"); return false; } return true } function validateLastName() { var str= form1.lname.value; if(str.length==0) { alert(" The last name cannot be empty"); return false; } return true; }
Web Page Programming with HTML,DHTML & JavaScript/Session 10/ 15 of 18
Form Validation(3) function validateEmail() { var str= form1.email.value;
if(str.length==0) { alert(" The Email field cannot be empty"); return false; } } function processForm() { disp=open("", "result") disp.document.write("<TITLE> Result Page </TITLE>"+"<PRE>") disp.document.write("<H2 ALIGN='CENTER'>"+ "Thanks for signing in"+"</H2>"+"<HR>"+"<BR><BR>") disp.document.write("First name \t\t: "+form1.fname.value+"<BR>") disp.document.write("Last name \t\t: "+form1.lname.value+"<BR>") disp.document.write("Email \t\t\t: "+form1.email.value+"<BR>") disp.document.write("Your Comments \t\t: "+form1.comment.value+"<BR>") disp.document.write("<PRE>")
Web Page Programming with HTML,DHTML & JavaScript/Session 10/ 16 of 18
Form Validation(4) if(disp.confirm("Is this information correct")) disp.close() } //--> </SCRIPT> </HEAD>
<BODY BGCOLOR="#FFFFFF"> <H2 ALIGN="CENTER"> Handling Form Events</H2><HR> <FORM name="form1"><P> First Name : NAME="fname" size=10 onBlur="validateFirstName()"> Last Name : onBlur="validateLastName()"> <P> Email : <INPUT TYPE="text" NAME="email" size=10 onBlur="validateEmail()"> Comments : <TEXTAREA NAME="comment" rows=4 cols=30 > Enter your comments </TEXTAREA> <P ALIGN="CENTER">onClick="processForm()"> <INPUT TYPE="reset"></P> </FORM> </BODY> </HTML>
Web Page Programming with HTML,DHTML & JavaScript/Session 10/ 17 of 18
Form Validation(5)
Web Page Programming with HTML,DHTML & JavaScript/Session 10/ 18 of 18