SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Wizard lukeurtnowski's Avatar
    Join Date
    Mar 2003
    Location
    Coronado
    Posts
    1,666
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)

    maximum file length?

    I have a form which allows uploads of image files, how do I check to make sure the name of that file is less than 30 characters?
    "Oh, and Jenkins--apparently your mother died this morning."

  2. #2
    I meant that to happen silver trophybronze trophy Raffles's Avatar
    Join Date
    Sep 2005
    Location
    Tanzania
    Posts
    4,662
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Code:
    var inp = document.getElementById('theformcontrol');
    inp.onblur = function() {
      if (this.value.length > 30) alert('filename is too long');
    }
    Maybe not onblur but onchange, it's up to you.

  3. #3
    SitePoint Wizard lukeurtnowski's Avatar
    Join Date
    Mar 2003
    Location
    Coronado
    Posts
    1,666
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Well, the form controls are Image[1]- Image[6], so I should place this in my <head>
    HTML Code:
    <script>
    for(x=1;x>6;x++) {
    var inp = document.getElementById('Image["+x+"]');
    inp.onchange = function() {
      if (this.value.length > 30) alert('filename of image #"+x+"is too long');
    }
    }
    </script>
    Thanks...
    "Oh, and Jenkins--apparently your mother died this morning."

  4. #4
    I meant that to happen silver trophybronze trophy Raffles's Avatar
    Join Date
    Sep 2005
    Location
    Tanzania
    Posts
    4,662
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Well, if you want to do this for all of them, then you can just do it via the parent, if there is one. For example, if these 6 form controls are in a fieldset with the id "formcontrols". Presumably they are all <input> elements of type "text". Also, if it's going in the head you need to do this onload. And I think you mean x<6, not x>6.
    Code:
    <script>
    window.onload = function() {
      var f = document.getElementById('formcontrols').getElementsByTagName('input');
      for(x=0;x<5;x++) {
        f[x].onchange = function() {
          if (this.value.length > 30) alert('filename of image #"+(x+1)+"is too long');
        }
      }
    }
    </script>

  5. #5
    SitePoint Wizard lukeurtnowski's Avatar
    Join Date
    Mar 2003
    Location
    Coronado
    Posts
    1,666
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    the alert statement is off, it doesn't alert the value, just(x+1)
    Thanks
    "Oh, and Jenkins--apparently your mother died this morning."

  6. #6
    I meant that to happen silver trophybronze trophy Raffles's Avatar
    Join Date
    Sep 2005
    Location
    Tanzania
    Posts
    4,662
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    You should be able to work this one out by yourself. Think about how strings can be defined.


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
  •