Link to home
Start Free TrialLog in
Avatar of qfren
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-data"

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;cursor:hand" id=Button1 name=Button1><font size="1"

face="Arial, Helvetica, sans-serif"><a href="javascript:alert('Click 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



SOLUTION
Avatar of Saqib Khan
Saqib Khan
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Avatar of David H.H.Lee
David H.H.Lee
Flag of Malaysia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial