Hi

Plz check this.

<html>

<head>

<title></title>

<script type="text/javascript" language="javascript"><!--

function addfile()
   {
       //reading number of current files and putting the number in a variable
       var filesno=document.getElementById("f_no").getAttribute("value");
       filesno++;//incrementing number of files

    var tbody = tb.tBodies.item(0);//storing the body content of the table into a variable
    var row = document.createElement("TR");//creating a row in a new ariable

    var td1 = document.createElement("TD");//creating  text node "td", with the value of number of files
    td1 .appendChild (document .createTextNode (filesno));

    var td3 = document.createElement("TD");//creating the input control and setting it's attribute
    var file=document.createElement ('<input>');
    file.setAttribute ('type','file');
    file.setAttribute ('name','fileupload'+filesno);
    td3 .appendChild (file );//adding the file control to the table data "td"

    //adding the "TD"s we created above to the row and adding the row to the table body 
    row.appendChild(td1);
    row.appendChild(td3);
    tbody.appendChild(row);

    //updating the hidden input with the new number of files
document.getElementById("f_no").setAttribute("value",filesno);
   }

function removefile()
   {
   //reading the number of rows in the table, ten deleting the last row
   if(tb.rows.length>2){
   tb.deleteRow(tb.rows.length-1);
   document.getElementById("f_no").setAttribute("value",document.getElementById("f_no").getAttribute("value")-1);
   }

   }

//--></script>


</head>

<body  style="text-align: center;color: white;background-color: gray;">
   <form action="upload.php" enctype="multipart/form-data" method="POST" >

   <input type="button" value="add file" onclick="addfile()" />
   <input type="button" value="remove file" onclick="removefile()" />

   <table id="tb" border="2" align="center">
   <thead>
   <tr>
   <td colspan="2">please choose files to upload</td>
   </tr>
   </thead>
   <tr><td>1.</td><td><input type="file" name="fileupload1" /></td></tr>
   </table>

   <input type="submit" value="upload the files" /> <input type="reset" value="clear fields" />
   <br/><br/>Amr Osama<br/>CodeCall.Net

   <input type="hidden" name="MAX_FILE_SIZE" value="100000000000000000000"/>
   <input  id="f_no" type="hidden" name="filesno" value="1"/>

  </form>
  </body>
</html>

This add file onclick. I need if I specified (5) multiple upload files, adding file should stop at number (5) and give warning message.

            var file=document.createElement ('<input>'); 

    If you also kept these elements in an array, you could easily see how many there were and respond appropriately.

    var file_inputs = [];
    function addfile()
    {
        if(file_inputs.length <= 5)
        {
            //.....
            var file = document.createElement('input');
            file_inputs.push(file);
        }
        else
        {
            //....
        }
    }

    And of course pop that array in removefile().

      Write a Reply...