Forms and JavaScript

Web Hosting That Works
WebMail

Home Page

New To Websites
  Website Primer
  Site Costs

eCommerce
  About eCommerce
  Shopping Cart
  Merchant Account

Data Centers
  Web Servers
  Data Protection
  RAID & Archive

Web Hosting
  Virtual Host
  Managed
  Dedicated
  Compare Plans
  FAQ
  Cities We Serve

Domain Name
  Naming Tips
  Register

HTML
  FrontPage
  Page Design
  Images
  HTML Tags
  Color Chart

JavaScript
  Introduction
  Resourses

Database
  Database Demo
  MySQL
  DBI
  Perl
  PHP

Programming
  Perl   JavaScript
  JSP vs ASP
  Tips

CGI
  Basics
  Email Forms
  Example Form
  Counter

eMarketing
  Search Engines
  Interactivity
  Marketing 101

EMail
  About Email
  OutlookExpress
  Spam Filter
  Email Viruses

FTP
  WS_FTP Program



Web Host Ratings

 



Processing Form Data

Once you've verified that the user has entered valid data, it's time to do something with it. In JavaScript, that's fairly easy.

We'll calculate the total adoption fee with the following function:

function calcTotal()
  document.orderForm.totalPrice.value =
    (document.orderForm.numberOrdered.value * 15.99);
} 

Simple, eh? The calcTotal() function simply takes the number supplied by the user in the numberOrdered field and multiplies it by 15.99.

The calculated total then gets printed in the "Total sponsorship fee" box.

And, of course, here's the HTML used to call the function:

Number of brains you'd like to sponsor
<INPUT TYPE="text" NAME="numberOrdered"
VALUE="" SIZE=10
  onChange="if(this.value) {
    if (!(isANumber(this.value, 'number of
brains'))) {
      this.focus();
    } else {
      calcTotal();
    }
  }">

This sends the number entered in numberOrdered to calcTotal() for processing, assuming it passes the isANumber() test. Notice that this JavaScript example doesn't require that the data be sent to the server for final processing. You can use similar techniques to create all kinds of online calculators, converters, or quizzes.

Note that at the beginning of our script, we define 'orderPlaced' (a global variable) and initialize its value to "false."

var orderPlaced = false;

If the user enters a number in the "number of brains" field, we change the value of orderPlaced to "true" by adding these lines to the isANumber() function:



  if (answer == 1) {
    orderPlaced = true;
  }

We use this variable as follows: 


Total price
<INPUT TYPE="text" NAME="totalPrice" SIZE=10
  onChange="if (orderPlaced) {
    alert('Total fee is a calculated field.');
    calcTotal(this.value);
  }">

Here, if the user attempts to change the value of the totalPrice field after a valid order has been placed (orderPlaced has been set to "true"), an alert pops up informing the user she is not allowed to change that field. In addition, calcTotal() is called again to restore the value of the totalPrice field.

Next: Checking Patterns




DaySite Web Hosting
1400 North Beach Street
Ormond Beach (Daytona), Florida 32174

386-672-6285
877-329-4839 (Sales Only Please)
Web@DaySite.Net
Cell Phone Email







Home | New To Websites | eCommerce | Web Hosting | Domain Name | HTML | Database | Programming | CGI | eMarketing | EMail | FTP

 
 
 

 

 


- Order Here -

Free
Domain Name Registration

With

Full Feature
Web Site Hosting

Just $15 a Mo.

Key Features
  Secure Servers
  Prof. Managers
  Personal Support
  Data Protection

Other Features
  Super Connectivity
  Ample Disk Space
  Extensive Email
  Spam Filters
  Virus Filters
  Web Site Stats
  CGI, Perl, PHP
  MySQL Database
  SSL Directory
  Free Domain Names

Call:
877-329-4839
(Toll Free)

eCommerce

FREE SSL

Secure Servers

Apache

Web Servers

MySQL Database Programming

Perl Database Programming

database programming

Since 1997

Domain Name Checker