KEMBAR78
javaScript tutorial | PPTX
JavaScript Tutorial
HTML form validation can be done by a
JavaScript.
• If a form field (fname) is empty, this function alerts a message, and returns
false, to prevent the form from being submitted:
• Example
• function validateForm() {
• var x = document.forms["myForm"]["fname"].value;
• if (x == null || x == "") {
• alert("Name must be filled out");
• return false;
• }
• }
This is the HTML that might goes with the
Javascript in the previous slide.
• <form name="myForm" action="demo_form.asp" onsubmit="return
validateForm()" method="post">
Name: <input type="text" name="fname">
<input type="submit" value="Submit">
</form>
This is one example of what JavaScript can do to validate input from a
user
In this example if a user enters their name the JavaScript code will give
the x variable that value.
If the user does not enter their name an alert box opens telling the user
that they must enter a name.
Data Validation
Data validation is the process of ensuring that computer input is clean,
correct, and useful.
• Typical validation tasks are:
• has the user filled in all required fields?
• has the user entered a valid date?
• has the user entered text in a numeric field?
• Most often, the purpose of data validation is to ensure correct input to a
computer application.
• Validation can be defined by many different methods, and deployed in
many different ways.
• Server side validation is performed by a web server, after input has been
sent to the server.
• Client side validation is performed by a web browser, before input is sent to
a web server.

javaScript tutorial

  • 1.
  • 2.
    HTML form validationcan be done by a JavaScript. • If a form field (fname) is empty, this function alerts a message, and returns false, to prevent the form from being submitted: • Example • function validateForm() { • var x = document.forms["myForm"]["fname"].value; • if (x == null || x == "") { • alert("Name must be filled out"); • return false; • } • }
  • 3.
    This is theHTML that might goes with the Javascript in the previous slide. • <form name="myForm" action="demo_form.asp" onsubmit="return validateForm()" method="post"> Name: <input type="text" name="fname"> <input type="submit" value="Submit"> </form>
  • 4.
    This is oneexample of what JavaScript can do to validate input from a user In this example if a user enters their name the JavaScript code will give the x variable that value. If the user does not enter their name an alert box opens telling the user that they must enter a name.
  • 5.
    Data Validation Data validationis the process of ensuring that computer input is clean, correct, and useful. • Typical validation tasks are: • has the user filled in all required fields? • has the user entered a valid date? • has the user entered text in a numeric field?
  • 6.
    • Most often,the purpose of data validation is to ensure correct input to a computer application. • Validation can be defined by many different methods, and deployed in many different ways. • Server side validation is performed by a web server, after input has been sent to the server. • Client side validation is performed by a web browser, before input is sent to a web server.