View Full Version : document.Register.field[xx].value validation

03-10-2005, 04:16 AM
Hi guys.

Have a curly one!

I have a registration form that is linked to a mailing list database.
As such, many of the form fields must be in the format 'field[xx]',
i.e. 'document.Register.field[xx].value'

The trouble is validation.
I have a validation script that validates textfields, dropdowns, radiobuttons and checkboxes etc.

{ errormessage += "\n\nPlease enter your last name.";

The validation does not like the 'field[xx]' bit.
An error might read "Error ... 'document.Register.field.xx' is blah blah blah...."

I have tried making the square brackets hexadecimal etc and even tried +'['+27+']' etc.

I have even replaced the 'field[xx]' with a name like 'lastname' in the form, validated that and then made the value of 'lastname' equal to the value of a hidden field called 'field[xx]' after the validation to then pass to the db but even this doesn't work.

Does anybody have a nice javascript way around this without me having to go into PHP or some server-side function?

That would be swell....


Warm Regards,

03-10-2005, 04:57 AM
Use the Square Bracket Notation (See my sig for more info)


In any case, you still need the server-side validation as JavaScript can be easily disabled or bypassed. That's the rule of thumb. Never mind the extra load for the server but that's how you make it totally secure. JavaScript validation is not meant to replace server-side validation, it just helps in making the page more interactive and gets rid of extra trip to the server everytime an invalid input is encountered.