Form - Validating input

They have: 11 posts

Joined: Jul 1999

Hi all,

I am a new member and new to JS programming. Presently, am designing a form and trying in vain to validate the input. I need help! Let's look at the problem.

Say, there are three textboxes, radiobuttons and a selection list. Two of the textboxes should accept only alphabets excluding special characters and the other only number. Only one radiobutton and an option should be selected.

Now, I want to validate using Javascript and mail it, how to do this? What is the difference with these:-
i ).....onClick="return validate(this.anyform);">
ii).....onClick="return validate();"
iii).....onClick="validate(this.anyform);"
iv)....onClick="validate();"
v)<Form name=anyform onsubmit="return validate(anyform);">
vi)<Form name=anyform onsubmit="validate(anyform);">
vii)<Form name=anyform onsubmit="validate();" >
viii)<Form name=anyform onsubmit="return validate();" >

Lastly, how to use one function to test similar form elements' input(for example textboxes; test input string). Should I declare an array of textboxes with same names? Sad

John Pollock's picture

He has: 628 posts

Joined: Mar 1999

I haven't done much in the form validation area, but I have seen sites with validation scripts. You might try one of these:

http://javascript.internet.com
http://www.wsabstract.com
http://www.javascripts.com

----------
Page Resource: http://www.pageresource.com
JavaScript City: http://www.javascriptcity.com

They have: 11 posts

Joined: Jul 1999

Thank you very much, Tazman. Quite monumental of you to share the knowledge. Will get to you, later on the development. Thanks again!.

------------------:)

* Thanks to Mr John for the recommendation.
Great site this; www.javascripts.com.( Dr.Joe Burns)Smiling

John Pollock's picture

He has: 628 posts

Joined: Mar 1999

tazman:
Thanks for the great post, it is very informative. Smiling

Sdaram:
You're welcome, glad the link helped. Smiling

----------
Page Resource: http://www.pageresource.com
JavaScript City: http://www.javascriptcity.com

They have: 99 posts

Joined: May 1999

i) Used when you want to check a forms element after a click event. You are passing a pointer to the form element to the validation routine and receiving a true or false as the return.

ii) same as i) but you are NOT passing the form element to check so you would need to know what you were checking in the validate() function.

iii) same as i) except you are not checking your return value.

iv) simply calling a function.

v) This forces the form to go thru the validate() function and based on thereturn value (true or false) the form will either submit or not. You are also passing the name of the form to the function which is usefull in the case of a page w/ multiple forms.

vi) same as v) except you are not checking the return so the form will submit regardless.

vii) same as v) except you are not passing the form name and not checking the return so the form will submit regardless.

viii) same as v) except you are not passing a form name.

Best way to do this is use method:
ONCHANGE="check_textbox(this.value)ou are then passing the form element value to the standard textbox validation routine. You could then validate and use window.alert("Bad data......" ) to warn user.
Wink

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.