CSS Lec-15 Ch-3 Forms and Event Handling.627cc73
CSS Lec-15 Ch-3 Forms and Event Handling.627cc73
CSS Lecture-15
Topic: Chapter-3 HTML Forms And Event Handling
HTML Form :
The <form> tag in HTML is used to create form for user input.
There are many elements which are used within form tag. For example:
<input>, <textarea>, <button>, <select>, <option>, <optgroup>,
<fieldset>, <label>.
Syntax:
JavaScript form objects represent an HTML form. HTML forms are very
powerful tool for interacting with users.
Event :
An event is a specific circumstance that is monitored by JavaScript and
that your script can respond to in some way.
HTML Events:
An HTML event can be something the browser does, or something a
user does.
Course: Java Script, Info Planet Programming Classes Prepared By: Atul Kabra, 9422279260
Course: Client Side Scripting, Prepared By: Atul Kabra, 9422279260
HTML form elements are way to gather input from the user, even when
form data is processed entirely by clients side JavaScript and never
submitted to the server.
Client side programs are event based they can respond to events on
individual form elements and this allows client side validation of data
before sending to the server.
Course: Java Script, Info Planet Programming Classes Prepared By: Atul Kabra, 9422279260
Course: Client Side Scripting, Prepared By: Atul Kabra, 9422279260
<html>
<head>
<title>Text Input Control</title>
</head>
<body>
<form id='#12' name='userform' action='server_code_file' method='GET
' >
First name: <input type = 'text' name = 'first_name' /> <br>
Last name: <input type = 'text' name = 'last_name' /> <br>
<input type='submit' value='Submit'/>
</form>
</body>
</html>
method: Defines how to pass the form data to the server when the form
is submitted.
onSubmit: Event fired up when the form is submitted and before the
execution of the action. This attribute associates a test
function on the form. If the function returns false, the form
data are not sent to server, we stay on the same page.
Course: Java Script, Info Planet Programming Classes Prepared By: Atul Kabra, 9422279260
Course: Client Side Scripting, Prepared By: Atul Kabra, 9422279260
<script>
function abc(){
if(document.getElementById("t1").value=="") {
alert("enter name");
return false;
}
return true;
}
</script>
</html>
Properties of form:
1) action: Read/Write string that reflects the action attribute of the
form.
2) elements[]: An array containing all of the elements of the form.
3) length: The number of elements in the form.
4) method: Read/Write string that specifies how the data is submitted
to server.
5) name: The name of the form.
Methods of form:
1) reset(): Resets the form elements to its initial values.
2) submit(): Submit the form to the server.
Form Events:
1) onReset(): Code is executed when the form is reset.
2) onSubmit(): Code is executed when form is submitted.
Course: Java Script, Info Planet Programming Classes Prepared By: Atul Kabra, 9422279260
Course: Client Side Scripting, Prepared By: Atul Kabra, 9422279260
</form>
</body>
<script>
function info(){
var form = document.getElementById("f1");
alert("Name of form = "+form.name);
alert("Elements on form = "+form.length);
alert("Action = "+form.action);
alert("Method = "+form.method);
form.reset();
}
</script>
</html>
Course: Java Script, Info Planet Programming Classes Prepared By: Atul Kabra, 9422279260