Discussion Locked

"smart" Javascript validation

0 helpful
4 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

I'm working on a contact us form that has a series of questions with the answers in pulldown menus. Each pulldown is something like this:

Please select
A
B
C
.............................................

Is there a way that the Javascript validation can make sure that they've selected one of the valid options (i.e., not the first or last one)?

4 replies

by burnettm

in the select,
{select name=nmatt onChange="getValidation(this.value)"}

The onChange event will automatically pass the value of the selected option into the function. Use the function to check if the selected value is correct.
Matt

by andremedeiros

Well... the tag has a paramater wich is called value. I'll explain it to you. It's very simple.
Let's imagine you have a piece of code like this:

This is the first part. This is a simple form that, when submitted, will call the validate() function that I will write a little more ahead. If the function returns true (the contact type is valid) the form is sent, if it returns false it will show an error popup.

The function validate(), which has to be before the form, will look something like this:

What this function does is to check the value of the selected option, and if it is different from "*" it lets you submit the form. If it isn't, it just shows an alert box.

Hope it helped

by andremedeiros

Well... the tag has a paramater wich is called value. I'll explain it to you. It's very simple.
Let's imagine you have a piece of code like this:

This is the first part. This is a simple form that, when submitted, will call the validate() function that I will write a little more ahead. If the function returns true (the contact type is valid) the form is sent, if it returns false it will show an error popup.

The function validate(), which has to be before the form, will look something like this:

What this function does is to check the value of the selected option, and if it is different from "*" it lets you submit the form. If it isn't, it just shows an alert box.

Hope it helped

This discussion is closed to new replies.