Hello and welcome to our community! Is this your first visit?
Register
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
    Posts
    1
    Thanks
    0
    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.

    i.e.
    if(WithoutContent(document.Register.field[27].value))
    { 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....

    http://intouch.fcnews.com.au/0503/subscribe.htm

    Warm Regards,
    Adman

  • #2
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,075
    Thanks
    0
    Thanked 256 Times in 252 Posts
    Use the Square Bracket Notation (See my sig for more info)

    document.Register.elements["field[27]"].value


    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.
    Glenn
    ____________________________________

    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
    •