PDA

View Full Version : making a portable form-field data validator


lawpoop
11-08-2003, 09:36 PM
Hey folks -

I'm a newbie to java script. I'm trying to make a portable data-validator for fields in an HTML form.

Ideally, it would work something like this:

<input type="text" name="test" onBlur=check_data(this.value, "date")>

The script would check the data against its data type (date, number, text) and then spit out an error if the data wasn't the correct type.

I've seen scripts that check the data when the user hits the 'submit' button. I would instead prefer to use the onblur event of each field.

To make it portable, it would then return focus to the field that the user just entered data into.

Where I'm running into problems is referring to the field name. I've tried referencing "this.parentnode.name", "this.parentnode.nodename", "this.parentelement.name", etc. to no avail. I would like it to work with NN 6.x and IE5.x, but nowhere have I found a comprehensive guide to what browser works with what javascript commands.

Can someone point me in the right direction?

Roy Sinclair
11-10-2003, 02:37 PM
Check this before you spend a lot of time developing something:

http://www.peterbailey.net/fValidate/

Willy Duitt
11-10-2003, 02:38 PM
Where I'm running into problems is referring to the field name. I've tried referencing "this.parentnode.name", "this.parentnode.nodename", "this.parentelement.name", etc. to no avail. I would like it to work with NN 6.x and IE5.x, but nowhere have I found a comprehensive guide to what browser works with what javascript commands.


Someone could possibly spot the problem if you
posted the relevant code you are working with.

glenngv
11-12-2003, 11:50 AM
pass the object itself (not it's value as you did) so that it's accessible to the function.

<input type="text" name="test" onBlur=check_data(this, "date")>