|
|
|
Creating Your Own Website For Free
The Internet gives us a two-way portal to the world. Unfortunately, most of us only use the Internet in one direction (i.e. receiving information). Many people never take advantage of the full potential the Internet gives - some don't even know what...
FLASHY WEB SITE DESIGNS ARE BAD FOR BUSINESS
Have you heard yourself saying, "I don't understand? I have a gorgeous site, a really cutting-edge splash page with a flash introduction, up-to-date technology, I paid a small fortune for this site, and I'm getting plenty of hits but no one is...
Making Searches Simple
One sticky point with many websites is this: they have
absolutely terrible search engines. It does make sense, in a
way, as searches are complicated to program for, and it takes
time to write or implement a search engine on your site. Still,
if...
Optimizing Google Adsense For Better Performance and More Money!
Optimizing Google Adsense For Better Performance and More Money!
By: Martin Lemieux So you want to make money with Google Adsense? I don't blame you, who doesn't want residual income! This article will show you how to better optimize Google...
When your graphic designer costs you money.
So how do you know when your graphic designer costs you financially and emotionally? When a file is not prepared correctly. When you go to press and have your media material produced in prints, and find out that the file was built incorrectly,...
|
|
| |
|
|
|
|
Validating Numerical Input with JavaScript
What? Make a mistake entering data? Who me? NO WAY! Right.
Every form of data input by a user should be validated in some form or fashion. If you get
clean data in, you won't get garbage out. This tutorial is going to explain how to validate
numerical data entered into a form using JavaScript.
First, let us begin with the code to insert the JavaScript into your HTML document.
Place these lines between the and tags.
This line tells the web browser to expect some JavaScript code and signal the beginning of
the script:
So now the format should look something like this:
My Title
Now on to validating the numerical input.
First we will create a function with one arument:
function validate(mydata){
These lines will test for a blank enty then prompt the user for input:
if (mydata == ""){ alert("Please enter a number.") }
Next we will create a for loop which will look at each character in the data until it
reaches the end:
for(var i=0;i < mydata.length;i++){
Now create a variable and assign the counter variable value to it:
var mydigit = mydata.charAt(i)
To screen out symbols, punctuation, and letters, place an if statement in the loop:
if(mydigit < "0" || mydigit > "9"){
The || in the if statement scans for both conditions.
The next line will alert the user to any mistakes he/she has made:
alert(mydigit + " is not a number.")
Here is the complete code including HTML: ============================================= Numerical Validation
| | | | | | |