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 6 of 6
  1. #1
    New to the CF scene
    Join Date
    Nov 2003
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Javascript Validation with a twist

    Hi,

    I have a form with 2 submit buttons with seperate actions one sends the form and the other uploads a file. I'm having a problem with users browsing for a file and clicking the wrong button. So i need to check to see if the attachment field has anything in it if the users clicks the wrong button and warn them that they have not uploaded their file and offer a prompt with text and a continue and cancel button. Any ideas?

    My code so far is:

    <script language="JavaScript">

    <!--

    function validate_filefield ( )
    {
    valid = true;

    if (myform.attachment.value.length > 0 )

    {
    return confirm('Warning you have not clicked the upload filebutton');
    valid = true;
    }
    return valid;
    }

    //-->

    </script>


    <form name="myform" method="post" action="gohere.cfm">


    <Input type=file name=attachment class="formfield" class="button">
    <input type=submit value="Upload File" name=attach onClick="this.form.action='sendfaxdocument.cfm';" class="button">
    <input type="submit" name="send" value="Send Details" onclick="this.form.action='job3.cfm'; return validate_filefield ();"></p>

    </form>

  • #2
    Regular Coder
    Join Date
    Aug 2004
    Location
    codegoboom@yahoo.com
    Posts
    999
    Thanks
    0
    Thanked 0 Times in 0 Posts
    How about disable-ing the one button until the onchange event takes place for the file input?
    *this message will self destruct in n-seconds*

  • #3
    New to the CF scene
    Join Date
    Nov 2003
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Unfortunately I have to have the option for users to continue or upload a file I just need to warn them.

  • #4
    Regular Coder
    Join Date
    Aug 2004
    Location
    codegoboom@yahoo.com
    Posts
    999
    Thanks
    0
    Thanked 0 Times in 0 Posts
    The cofirm() method should work... there are many examples of that around here, btw.
    *this message will self destruct in n-seconds*

  • #5
    New to the CF scene
    Join Date
    Nov 2003
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Yep got it to work,

    thanks for the tips

  • #6
    Senior Coder
    Join Date
    Jul 2004
    Location
    New Zealand
    Posts
    1,315
    Thanks
    0
    Thanked 2 Times in 2 Posts
    What if they have Javascript disabled? What does your form do then? Why not seperate the form into two. It makes a lot more sense, simplifies processing, and is safer.
    Forget style. Code to semantics. Seperate style from structure, and structure from behaviour.
    I code to specs, and test only in Firefox (unless stated otherwise).


  •  

    Posting Permissions

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