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?

Link to comment
Share on other sites

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>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.