...

View Full Version : Form validation on upload feild?



angst
08-19-2005, 08:53 PM
Hi,

I'm wondering how i can validate if a user has selected a file before hitting the upload button on an input=file field?

like:
<input type="file" name="userfile[0]">

I've been looking around, but haven't found anything yet,

any ideas?

thanks in advance for your time!
-Ken

martin_narg
08-19-2005, 09:16 PM
if(document.elements["userfile[0]"].value == "") {
// .....
}


Hope this helps

m_n

angst
08-19-2005, 10:38 PM
sorry, i'm new to javascript,
and i'm not sure what to do with this,

will this check if a file has been select while hiting the submit button?

thanks again for your time!
-Ken

martin_narg
08-19-2005, 11:54 PM
Above your closing </head> tag:


<script type="text/javascript">
function validate(f) {
if(f.elements["userfile[0]"].value == "") {
alert("Please select a file");
return false;
}
return true;
}
</script>

Your form tag:


<form name="PutYourFormNameHere" method="post" action="PutYourFormHandlerPageHere.asp" onsubmit="return validate(this);">


Hope this helps

m_n



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum