qfren
asked on
check the size with javascript before upload.....
hi:
look at this coding below..
this is a coding where user can upload the file to server...its works fine.
-------
<script>
var nfiles =3;
function Expand(){
nfiles++
var adh = '<BR> File '+nfiles+' :<input type="file" name="File'+nfiles+'">';
files.insertAdjacentHTML(' BeforeEnd' ,adh);
return false;
}
</script>
<script>
function onSubmitForm() {
var formDOMObj = document.frmSend;
var confirmUpload
if (formDOMObj.File1.value == "" && formDOMObj.File2.value == "" && formDOMObj.File3.value ==
"" )
alert("No valid file(s) selected! Please press the browse button and pick a file.")
else
return true;
return false;
}
</script>
<table width="50%" border="0" align="center" cellpadding="0" cellspacing="0"
bordercolor="#9933CC">
<tr>
<td>
<form name="frmSend" method="POST" enctype="multipart/form-da ta"
action="uploadTester.asp" onSubmit="return onSubmitForm();">
<Div ID=files>
File 1: <input name=File1 type=file onchange="CheckSize()"><br >
File 2: <input name=File2 type=file onchange="CheckSize()"><br >
File 3: <input name=File3 type=file onchange="CheckSize()">
</Div>
<Input Type=Button Value="Add file" OnClick=return(Expand())
Style="border=0;background =#6699FF;c ursor:hand " id=Button1 name=Button1><font size="1"
face="Arial, Helvetica, sans-serif"><a href="javascript:alert('Cl ick to add more file to upload
.');"> << What
is this?</a></font> <br>
<br>
<input name=submit1 type=submit id=submit1 style="margin-top:4;" value="Upload">
</form>
</td>
</tr>
</table>
<p><br>
------
However, now i wanna add some coding for << onchange="CheckSize()" >>
i wan to do the coding in javascript to that checksize() function so that,
fucntion will check so that when the user click the "browser" and choose a file,it will check the size of file first....If the size exceed 100K, there is a message --alert("File Size Exceed
100KB"). Then, that input will BLANK again so that user can re-choose..
One more thing hv to mention is as u can see,user can "Add file" to upload more than 3 file
right?So, maybe there is a user add until 10 files to upload. Let say, the first 5 files is
ok(means doenst exceed the size). But file number-6 was exceed the size, so ONLY the input
number-6 will blank; the previous 5 input(which doenst exceed the size) nothing change on it. Means every input will be check...
Let me know if u guys dont understand my Q
q
look at this coding below..
this is a coding where user can upload the file to server...its works fine.
-------
<script>
var nfiles =3;
function Expand(){
nfiles++
var adh = '<BR> File '+nfiles+' :<input type="file" name="File'+nfiles+'">';
files.insertAdjacentHTML('
return false;
}
</script>
<script>
function onSubmitForm() {
var formDOMObj = document.frmSend;
var confirmUpload
if (formDOMObj.File1.value == "" && formDOMObj.File2.value == "" && formDOMObj.File3.value ==
"" )
alert("No valid file(s) selected! Please press the browse button and pick a file.")
else
return true;
return false;
}
</script>
<table width="50%" border="0" align="center" cellpadding="0" cellspacing="0"
bordercolor="#9933CC">
<tr>
<td>
<form name="frmSend" method="POST" enctype="multipart/form-da
action="uploadTester.asp" onSubmit="return onSubmitForm();">
<Div ID=files>
File 1: <input name=File1 type=file onchange="CheckSize()"><br
File 2: <input name=File2 type=file onchange="CheckSize()"><br
File 3: <input name=File3 type=file onchange="CheckSize()">
</Div>
<Input Type=Button Value="Add file" OnClick=return(Expand())
Style="border=0;background
face="Arial, Helvetica, sans-serif"><a href="javascript:alert('Cl
.');"> << What
is this?</a></font> <br>
<br>
<input name=submit1 type=submit id=submit1 style="margin-top:4;" value="Upload">
</form>
</td>
</tr>
</table>
<p><br>
------
However, now i wanna add some coding for << onchange="CheckSize()" >>
i wan to do the coding in javascript to that checksize() function so that,
fucntion will check so that when the user click the "browser" and choose a file,it will check the size of file first....If the size exceed 100K, there is a message --alert("File Size Exceed
100KB"). Then, that input will BLANK again so that user can re-choose..
One more thing hv to mention is as u can see,user can "Add file" to upload more than 3 file
right?So, maybe there is a user add until 10 files to upload. Let say, the first 5 files is
ok(means doenst exceed the size). But file number-6 was exceed the size, so ONLY the input
number-6 will blank; the previous 5 input(which doenst exceed the size) nothing change on it. Means every input will be check...
Let me know if u guys dont understand my Q
q
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.