Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Mar 2005
    Thanked 0 Times in 0 Posts

    document.Register.field[xx].value validation

    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,

  • #2
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Thanked 256 Times in 252 Posts
    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.

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins


    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts