When i use a 'file field' on a form to browse for an file, i want to just be able to select *.jpg's, so a user cannot select any file other than a jpg (or perhaps even see anyfile other than a jpg)
Best to catch the onSubmit event, check the make sure that field ends in '.jpg' and if it doesn't alert the user and cancel the submit by returning false. If it matches the do a form.submit.
You won't be able to limit thte file browser with JS, thats an OS function.
i really should have known how to do this, all coding is similar
Im using:
-----------------
function onSubmitForm() {
var formDOMObj = document.frmSend;
var v=formDOMObj.attach1.value;
if (formDOMObj.attach1.value == ""
alert("Please press the browse button and pick a file."
else
if(v.substring(v.lastIndexOf('.')).toLowerCase()=='.jpg')
return true;
else
alert('Files must be .jpg');
return false;
return false;
}
--------------
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.