I LOVE YOU even I don't know your name It has been more than three months or more but still I don't know your name Your beauty and the deep love that I have Make me to be afraid of you, , , to speak to you even ask you your name.....
When using java-script to check a form, the first thing you need is the onsubmit event handler. This event handler specifies a script that is executed when the user submits the form. That script is where you check whether certain fields have a value, whether the user has checked at least one checkbox, and any other checks you deem necessary.
The form validation script needs to access the form in the HTML page to determine what values the user has filled in. So first we have to enter the form by means of the Level 0 DOM. The general syntax for accessing a form element is:
document.forms[number].elements[number]
When the page is loaded, java-script makes an array forms in which it puts all the forms that are on the page. The first form is forms[0], the second is forms[1] etc.
Each form has another array in which java-script puts all the elements in the form. The first elements is elements[0], the second elements[1] etc. Every , is an element.
In some cases, it's better to use the names of the forms and elements. In HTML, you have to give a name to each form and each element, like:
The advantage of using names is that you can put all elements somewhere else in the page and still have a working script, while a script using numbers will have to be changed. After all, the input box city is document.forms[0].elements[2] in the example above, but when you suddenly put it at the top of the form, it becomes document.forms[0].elements[0] and you have to change the script.
When you start writing your own scripts using the code snippets below, it is always very important to know exactly how your form is built. To help you, I wrote a form printing script that prints out the form structure for you.
First of all, you should have a clear idea of what happens when a user submits a form that has a java-script validation script:
The form is checked by a java-script like the one described below. If the script finds a mistake the submission is halted here. The user sees an alert and is asked to re-enter some data.
If nothing is wrong—or if java-script is disabled—the form is sent to the server and is processed by a CGI script.
If the CGI script finds a mistake it generates some HTML with an error message and sends it back to the user. In this case the user has to go back to the form, re-enter some values and again submit it.
If no mistakes are found, the CGI script does whatever it has to do with the data and directs the user to a Thank You page.
As you see, the form is checked for mistakes twice: by the java-script and by the CGI script. The CGI check always works, since CGI is server side. The java-script check only works when the user has java-script enabled. It follows that the CGI check is the most reliable: it always works regardless of what browser is used. Then why use a java-script check too?
The java-script check is very useful in addition to the CGI check because it can catch mistakes before the form is actually sent to the server. Thus the user doesn't have to use his back button to return to the form, something that may cause confusion, and then search for the incorrect form field, which may cause even more confusion. Therefore the java-script check is more user friendly than the CGI check.
In addition, when you use java-script the server doesn't need to spend quite so much time in error handling and is thus a little quicker. This only matters if you have lots and lots of forms, but it's good to keep it in mind.
So java-script is not a fail-safe method of catching mistakes, but it is very useful as an addition to CGI checks since it lightens the load on the server and is more user friendly. Therefore I recommend using both java-script form checks and CGI form checks. This way, you get both user friendliness and security.
However, this page contains a more complete overview of how to write a basic form validation script.
On this page I give the code you need for checking user input in a form. Using these bits of code, you can write your own scripts to validate forms
I can't give you a complete script, because each form and each check are different. You'll have to use the elements I explain on this page to build your own script. I created an example form and script that you can study to get the hang of it.
var emailfilter=/^\w+[\+\.\w-]*@([\w-]+\.)*\w+[\w-]*\.([a-z]{2,4}|\d+)$/i
function checkmail(e){ var returnval=emailfilter.test(e.value) if (returnval==false){ alert("Please enter a valid email address.") e.select() } return returnval }