멀티 파일업로드 자바스크립트로 생성하기.

<html>
<script language="javascript">
    // 멀티 파일 추가(+)/삭제(-)
    function multyFile(cnt) {
       
  var elmCnt = parseInt(document.PageForm.fcnt.value);
        elmCnt = elmCnt + parseInt(cnt);
  if(elmCnt < 1) {
   elmCnt = 1;
  }
  document.PageForm.fcnt.value = elmCnt
        //alert(elmCnt);
        var itemText = ""
  for(i = 1; i <= elmCnt; i++) {  
   itemText = itemText + "<tr><td><input type='file' name='file"+ i +"'></td></tr>";    
  }
  areaFile.innerHTML = "<table width='100%' cellpadding='0' cellspacing='0' border='0'>"+ itemText +"</table>";
      
    }
   
</script>
<body>
<form name="PageForm">
 <input type="hidden" name="fcnt" value="1"> 
    <span id="areaFile">
        <input type="file" name="file1">
    </span>
 <br>
    <input type="button" value="++" onclick="multyFile(1);"> &nbsp;&nbsp;
    <input type="button" value="--" onclick="multyFile(-1);"><br>
</form>
</body>
</html>

댓글