...

View Full Version : ASP JS good stuff



sasha85
09-28-2007, 04:09 AM
this is a wonderful asp js that checking that only pdf files will upload


<script language=vbscript>
sub Checkform()

if lcase(right(myfrm.file.value,4)) <> ".pdf" then
alert "not pdf File.Size"
myfrm.reset()
end if
end sub
</script>

<form action=addAttachment.asp enctype="multipart/form-data" method=post name=myfrm id=myfrm>
<input type=file name=file id=file onchange="Checkform()">
<input type=button value="add file">
</form>


i want to export it to jpg and gifs


<script language=vbscript>
sub Checkform()


if lcase(right(myfrm.file.value,4)) <> ".pdf" and lcase(frm.file.value,3)) <> ".jpg" and lcase(right(myfrm.file.value,3)) <> "jpeg" then
alert "not pdf File.Size"
myfrm.reset()
end if
end sub
</script>

<form action=addAttachment.asp enctype="multipart/form-data" method=post name=myfrm id=myfrm>
<input type=file name=file id=file onchange="Checkform()">
<input type=button value="add file">
</form>

i thought that if i will add and\or in the "if", i will solve this...but as you see i was wrong...can you help me?

by the way if someone knows how to check the size of the choosen file in this stage i will be happy like a little girl!:)

Whatever Jr.
09-28-2007, 07:48 AM
Hi,

Try this:

<script type="text/javascript">
function Checkform() {
var o = document.getElementById('file');
var ex = o.value.substring(o.value.lastIndexOf('.')+1);
if(ex.toLowerCase() == 'gif' || ex.toLowerCase() == 'jpg' || ex.toLowerCase() == 'pdf') {
return true;
}
else {
alert('extension not allowed');
return false;
}
}
</script>

<form action="addAttachment.asp" enctype="multipart/form-data" method="post" name="myfrm" id="myfrm" onSubmit="return Checkform();">
<input type="file" name="file" id="file">

<input type="submit" value="add file">
</form>

HTH, AA

sasha85
09-28-2007, 01:35 PM
man it's realy good!:)

sasha85
09-29-2007, 01:54 AM
never mind:) i will use the first script only



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum