If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Enjoy an ad free experience by logging in. Not a member yet? Register.

Server-side validation is generally best (users can disable javascript - or you can force the form to submit via JavaScript, so if it's disabled the form can't submit.)

Basically, you get the value/selectedIndex of the form inputs via the DOM. Client-side validation that I like (give the form a name; change submit button to input type="button" and add onclick="return validateForm(this.form);"):

If anyone knows of a website that can offer ColdFusion help that isn't controlled by neurotic, pedantic jerks* (stackoverflow.com), please PM me with a link.* The neurotic, pedantic jerks are not the owners; just the people who are in control of the "popularity contest".

Server-side validation is generally best (users can disable javascript - or you can force the form to submit via JavaScript, so if it's disabled the form can't submit.)

Doing that would prevent those who don't have JavaScript from ever being able to submit the form. Depending on which country your visitors are in and what anti-discrimination laws apply in their country not allowing those without JavaScript to use a form may be illegal and a large fine might result.

There are some groups of disabled people who either use browsers that don't support JavaScript or where enabling JavaScript would make it impossible for them to interact with the page and such people have been known to take legal action when sites discriminate against them by not providing them with a way to interact with the site. There was one case where a large retailer whose site discriminated by requiring JavaScript that was settled out of court for a few million dollars.

Even where your site is unimportant enough to not fall foul of anti-discrimination laws, do you really want to annoy some of your visitors and have them telling all your friends how useless your site is?

The "return true;" line belongs at the end of the function. Do all of the validation parts (name, address, ....) and their respective "return false;" lines first. If the user gets past all of those error checks, then the function returns the true value and the form submits.

Drop down menu issue

Originally Posted by jalarie

The "return true;" line belongs at the end of the function. Do all of the validation parts (name, address, ....) and their respective "return false;" lines first. If the user gets past all of those error checks, then the function returns the true value and the form submits.

Yes thanks got it working now.. How much would the code change for using drop down menus. I have tried with the below but can't seem to get it working.

Don't forget to get rid of the debugging alert() calls before you make the page live. You don't want people checking the checkbox that most broswers add to alert() to make it more useful for debugging.

Doing that would prevent those who don't have JavaScript from ever being able to submit the form. Depending on which country your visitors are in and what anti-discrimination laws apply in their country not allowing those without JavaScript to use a form may be illegal and a large fine might result.

There are some groups of disabled people who either use browsers that don't support JavaScript or where enabling JavaScript would make it impossible for them to interact with the page and such people have been known to take legal action when sites discriminate against them by not providing them with a way to interact with the site. There was one case where a large retailer whose site discriminated by requiring JavaScript that was settled out of court for a few million dollars.

Horsepoo. Specify an authority, please. A person of your stature ought not to propagate silly stories like that.

All the code given in this post has been tested and is intended to address the question asked.
Unless stated otherwise it is not just a demonstration.

felgall might wish to replace {2,4} by {2,6}. In reality the domains travel and museum are very rarely found. In fact, never in my experience.

Simply testing for the presence of an @ is completely inadequate. Even testing for the presence of a single @.

Another (additional?) way is to cause the user to enter his email address twice to confirm. That still does not offer complete protection, but if the user cannot get his own email address correct that is his responsibility. Nothing will prevent typos such as @gmial.com.

Last edited by Philip M; 01-17-2013 at 08:53 AM.

All the code given in this post has been tested and is intended to address the question asked.
Unless stated otherwise it is not just a demonstration.

address=document.forms[0].address.value; // avoid using the same name for an HTML element and a Javascript variable. Always include the var keyword to make your variable local to the function.

It's a really bad idea to use NUMBERED forms. (document.forms[0])
And NAMED forms are considered obsolete.
You should give IDs to your <form> tags.

if (address == '') {
Be aware that form validation of the pattern if (document.formname.formfield.value == "") - that is blank - is barely worthy of the name, and virtually useless, as even a single space, an X or a ? will return false, that is pass the validation. A proper name may only contain letters, hyphen, space and apostrophe. Numeric values, such as zip codes and phone numbers, should be validated as such. Ditto email addresses. This topic has been covered many times before in this forum.

<javascript> should be <script type = "text/javascript">

I have the idea that your grasp of Javascript at present is not really up to what you are trying to achieve.

Last edited by Philip M; 01-17-2013 at 08:54 AM.
Reason: Typo

All the code given in this post has been tested and is intended to address the question asked.
Unless stated otherwise it is not just a demonstration.