Software and services at affordable prices

RichoSoft is a non-profit making site

Site documents

Newsletter - Sign up to my Newsletter

About  templates

New members area - free to join - exclusive content & offers
|

Useful Javascript Snippets

FOR ALL EDITORS

Here are some useful javascript snippets:


Validating a Number in a Range

Enter a Number

Want to ensure that the user enters a number within a certain range in a text box on a form?

Enter a number in the box above and click Submit to try it. If you enter a correct value the response in this example will post the data back to this form.  

Here’s how to do it.

In your code for the Input Box add :

Email Validation

Want to check if a valid email address has been entered? This is a very simple basic checking script, for a more sophisticated and thorough checking script watch this space!

Enter an invalid email in the box above and click submit to try it. If you enter a valid email the form will be submitted (In this example back to this page.)

Here’s how to do it.


In your code for the Input Box add :

Email Address

Self emptying Text Box

Want some initial text in a text box on a form, but want it to disappear as soon as the user clicks to enter data?

Click the box above to try it.

Here’s how to do it.


In your code for the Input Box add :

e.g.  <input type="text" value="Enter your name" name="fName" onFocus="if (this.value==this.defaultValue) this.value='';" onBlur="if ((1) && (this.value=='')) this.value=this.defaultValue;">


Check Password entry

Password

Confirm

Want to check if two passwords entered on a form are the same before sending the data?

Enter 2 different passwords in the boxes above and click submit to try it.  

If you enter 2 identical passwords the form will be submitted (In this example back to this page.) (Name the text boxes password and password1)

Here’s how to do it.


In your code for the 2nd Input Box add :

e.g.  

<form action="" method="post" target="_self" enctype="application/x-www-form-urlencoded">

  <input type="submit" name="submit" value="Submit" >

  Password :<input type="password" name="password" size="9" style="width:80px;" value="" >

  Confirm Password :<input type="password" name="password1" size="9" style="width:80px;" value="" onBlur="if ((this.value != this.form.password.value)) alert('The passwords are not the same.');">

</form>

more scripts