Jump to content

Question on HTML form on javascript


merck_delmoro

Recommended Posts

this is my code:

<script type="text/javascript">
function addRow(table_id){
var clone;
var rows=document.getElementById(table_id).getElementsByTagName('tr');
var index=rows.length;
var newcopy = document.getElementById(table_id);
var tbo=newcopy.getElementsByTagName('tbody')[0];
clone=rows[index-1].cloneNode(true);
tbo.appendChild(clone);
}

function delRow(table_id,button){
var row = button.parentNode.parentNode;
var tbo = document.getElementById(table_id).getElementsByTagName('tbody')[0];   
tbo.removeChild(row);
}

</script>
<form method="post" action="upload_file.php" enctype="multipart/form-data">
<table id="mytab">
<tr>
<td>Upload File <input type="file" name="file[]" onchange="addRow('mytab')" /> <input name="del_row" type="button" value="Remove Row" onclick="delRow('mytab',this)"/></td>
</tr>
</table>
<input type="submit" value="UPLOAD">
</form>

this code will duplicate the <input type="file"> but it copies its content on it what should I change?

try this:

 

<script type="text/javascript">
function addRow(table_id){

var tbo=document.getElementById(table_id).getElementsByTagName('tbody')[0];	

var row = document.createElement('tr');
var cell = document.createElement('td');

var clone = document.createElement('input');
clone.type='file';
clone.name='file[]';
clone.onchange=function(){addRow('mytab');};

var del = document.createElement('input');
del.type='button';
del.name='del_row';
del.onclick=function(){delRow('mytab',this);};
del.value="Remove Row"

var text = document.createTextNode('Upload File ');
var space = document.createTextNode(' ');

cell.appendChild(text)
cell.appendChild(clone);
cell.appendChild(space);
cell.appendChild(del);

row.appendChild(cell);
tbo.appendChild(row);
}

function delRow(table_id,button){
var row = button.parentNode.parentNode;
var tbo = document.getElementById(table_id).getElementsByTagName('tbody')[0];   
tbo.removeChild(row);
}

</script>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.