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 5 of 5

Thread: validation help

  1. #1
    Regular Coder
    Join Date
    May 2004
    Location
    The First State
    Posts
    233
    Thanks
    9
    Thanked 0 Times in 0 Posts

    validation help

    I am using this script to validate a field called "field"

    <SCRIPT LANGUAGE="JavaScript">

    <!-- Begin
    function verify() {
    if (document.fileupload.first.value=="") {
    alert("Please attach a file to upload");
    return false;
    }
    }
    // End -->
    </script>

    However, when I use a name like this for the field "wcsave_a9-photofile" as
    document.fileupload.wcsave_a9-photofile.value==""

    it will not validate. Is there any reason for this?

    thanks in advance

  • #2
    Regular Coder
    Join Date
    Nov 2002
    Location
    Manchester, UK
    Posts
    533
    Thanks
    4
    Thanked 1 Time in 1 Post
    the JS could think that the "-" in the name is a minus and might be trying to do a calculation?

    that's all I can think of at the mo!

  • #3
    Regular Coder
    Join Date
    May 2004
    Location
    The First State
    Posts
    233
    Thanks
    9
    Thanked 0 Times in 0 Posts
    I replaced the "-" with a "_" and it seems to work fine. Thanks for the help

  • #4
    Regular Coder
    Join Date
    Nov 2002
    Location
    Manchester, UK
    Posts
    533
    Thanks
    4
    Thanked 1 Time in 1 Post
    happy to help glad you got it sorted!

  • #5
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    10,966
    Thanks
    0
    Thanked 236 Times in 233 Posts
    Another way of accessing field is the "elements" collection using the bracket notation. This is specially helpful if the name of the field has special characters that are illegal when accessed using the dot notation, as in this case.

    if (document.fileupload.elements["wcsave_a9-photofile"].value=="") ...


  •  

    Posting Permissions

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