|
|
|
Internet Dating – It’s Not For Geeks
Six months ago an old school friend and I were chatting over coffee, putting the world to rights as women do. She was bemoaning her lack of success in meeting the “right sort” of men. I asked her if she had tried using an internet dating...
Online Dating Tips - Tip #1 - Honesty
There's really no point in telling somebody that you're tall, tanned and toned if in reality, you're more average height, pale and allergic to the gym.
Tell the truth
Sure we would all like to come across as being super-gorgeous but...
Take Off the Rose-Colored Glasses When Dating
Robin was giving me an anatomy of her divorce. “There were signs,” she said. “Plenty of them. I just ignored them.” “The counselor told me to ignore how he treated other people,” said Manuela, “and concentrate on how he treated me. But one day I...
Understanding The Risks Of Online Dating
The Risks of Online Dating
There is no question that the popularity of online dating has
revolutionized the way potential couples meet each other. These
days, it is not uncommon for the average single person to
participate in an online...
Want To Go Dating? Find Out How To Make Your Next Date A Hit!
With all the personals and online dating sites popping up everywhere, it seems like it's getting easier and easier to find a date online. However, without a proper dating game plan, you are going to fail... big time! Discover the 7 secrets of...
|
|
| |
|
|
|
|
|
from our sponsors
Internet Home Business Training Course
|
Validating Form Input in JavaScript
This time we'll make a form that collects information about the visitor at your site. You must have filled-in copious registration forms or survey forms where you had to enter your name, your email, your address, etc. Sometimes users, intentionally or unintentionally, enter wrong information that can either spoil your database scheme or give you lots of useless data and hence, waste your precious server space.
To avoid such problems, as much as it can be managed, we programmatically try to make sure, that data is entered in an orderly fashion, and no unusable fields are entered. Checking individual fields of the form does this.
We'll see a form here with three fields: Name, Phone and Email. In this form, no field should be left blank, there should be no numbers in the Name field [1,2,3,4,.], and in the Email field, no email should be without the "@" sign. We can carry out more complex validations, but at the moment, these three should suffice.
/// Remove the extra dots while testing. They have been just inserted so that some email programs don't freak out at the presence of a JavaScript in the email.
<..script language="JavaScript1.2"> function CheckName(HoldName) { NoNumThere='true'; for(i=0; i { for(j=0; j<10; j++) { if(HoldName.charAt(i)==j.toString()) { NoNumThere='false'; break; } } if(NoNumThere=='false') { break; } } return NoNumThere; } function CheckMail(HoldMail) { IsValid='true'; if(HoldMail.indexOf("@")<=0) { IsValid='false'; } return IsValid; } function checkfields() { var AllFilled='true'; for(i=0; i<3; i++) { if(visitor.elements[i].value.length==0) { alert("The field [" + visitor.elements[i].name + "] can not be left blank."); AllFilled='false'; visitor.elements[i].focus; return; } } if(AllFilled=='true') { var NameValid=true; var EmailValid=true; NameValid=CheckName(visitor.vname.value); EmailValid=CheckMail(visitor.vemail.value); if(NameValid=='false') { alert("Sorry, your name can not contain numbers."); visitor.vname.focus; } if(EmailValid=='false') { alert("Sorry, this does not seem like a valid email address."); } } if(NameValid=='true' & EmailValid=='true') { alert("RIGHTO!!!"); } }
Copy and paste the code as it is, and save the entire content as a new HTML page. Then load it on to your browser. Unless you see the result, it'll be difficult to follow
Didn't Find What You Were Looking For?
Try a Specialized Search HERE
the script if you do not have prior programming background. The first condition is, none of the fields can be submitted blank. Click on the submit button without entering anything and observe the reaction.
Here, we are making ample use of the recently learnt for(){.} loop. Then we have used function too, to carry out certain validations. Our main function, checkfields(), is associated with the OnClick attribute of the "Submit" button, that is, when you click on the "Submit" button, this function gets triggered.
Some new terms in today's script are: true, false, charAt(), toString(), break, indexOf(), string.length, and orm.elements[ ].
A quick explanation to make things easier:
If at 10:30 pm, I say, "It is night", then
var fact='true'
and if I say at 10:30 pm that "It's afternoon", then
var fact='false'
Which explains the use of true and false, which are also called Boolean operators, which means, a Boolean variable can either be true or false, but NEVER both.
Until we learn about arrays, every character in a string has an index position. For instance, if we have
var city="Delhi"
then city.charAt(0)="D", city.charAt(1)="e", city.charAt(2)="l"...city.charAt(4)="i".
toString(), converts another data type to a string data-type. For example,
var num1=31 var num2=21 var char1=num1.toString() var char2=num2.toString()
So,
num1+num2=52 and char1+char2=3221
In the second case, instead of being added, the variables are being concatenated, which indicates that they are strings, not numbers. We'll see its application later.
break, true to its name, breaks something. In this case, it breaks the loop in which it occurs, and takes the execution of the program to the line immediately after the loop, without meeting the condition required to complete the loop.
indexOf() tells us about the position of a particular character in a string. Look its use in the following code:
var city="Delhi"
Referring to this code, city.indexOf("e") should give us a value 1 and city.indexOf("h") should give us a value 3. city.indexOf("z") should give us a value less than zero, indicating that it does not belong to the given string.
String.length gives us the length of the string, for instance, if city="Delhi", then city.length would give us 5.
Again, elements[ ] is an array, and we haven't dealt with them yet, so we leave the rest of the explanation to the next section.
About the Author
Amrit Hallan is a freelance web designer. For all web site development and web promotion needs, you can get in touch with him at amrit@bytesworth.com or http://www.bytesworth.com. For more such articles, visit http://www.bytesworth.com/articles You can subscribe to his newsletter [BYTESWORTH REACHOUT] on Web Designing Tips & Tricks by sending a blank email at bytesworth-subscribe@topica.com
|
|
|
|
|
|