SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Evangelist
    Join Date
    Mar 2004
    Location
    Fort Lauderdale
    Posts
    522
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    file upload validation

    Hi,

    Please take a look at this url
    http://www.trainerdirectory.net/trai...=addeditphotos

    I would like to get a very good validation script that:

    1. disables the submit button unless one of the radio buttons is selected
    and the file url is present
    2. is it possible to validate the size of the file with javascript?

    Thanks.
    Paul

  2. #2
    SitePoint Addict
    Join Date
    Nov 2003
    Location
    Malmoe, Sweden
    Posts
    265
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    1. At first when the page is loaded you will have to make the button disabled.
    Code:
    <input type="submit" name="btnSubmit" value="Send File" disabled="disabled" />
    Then on your radio button:
    Code:
    <input type="radio" name="pPic" value="Face" onclick="javascript:this.form.btnSubmit.disabled=false;" />
    2. No can do.

  3. #3
    SitePoint Member
    Join Date
    May 2004
    Location
    belgium
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Nr2 can be done.

    But it only works for image-files.
    No ActiveX, no components, just a small script and a hidden field.
    Code:
    <form name="formData">
    <input type="file" name="uploadfile" onchange="setdumy(value)">
    </form>
    <img style="visibility:hidden;position:absolute;" id=dumy onload="checksize()">
    <script language="javascript">
    function setdumy(file)
    {
    dumy.src=file;
    }
    function checksize()
    {
    if (dumy.fileSize>51200)
    {
    formData.reset();
    alert("fileSize should be less than 50K!");
    }
    }
    </script>
    Greetz

  4. #4
    SitePoint Addict
    Join Date
    Nov 2003
    Location
    Malmoe, Sweden
    Posts
    265
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by palm
    Nr2 can be done.

    But it only works for image-files.
    And only on user agents that supports the fileSize property on the image object. This is NOT recommeded use as neither Mozilla nor Firefox supports it. Actually I think this is only supported by IE.


Bookmarks

Posting Permissions

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