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?
| SitePoint Sponsor |





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."

Maybe not onblur but onchange, it's up to you.Code:var inp = document.getElementById('theformcontrol'); inp.onblur = function() { if (this.value.length > 30) alert('filename is too long'); }





Well, the form controls are Image[1]- Image[6], so I should place this in my <head>
Thanks...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>
"Oh, and Jenkins--apparently your mother died this morning."

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>





the alert statement is off, it doesn't alert the value, just(x+1)
Thanks
"Oh, and Jenkins--apparently your mother died this morning."

You should be able to work this one out by yourself. Think about how strings can be defined.
Bookmarks