Hello,
I found this tutorial and would like to change it to my requirements
I'm looking for a way to rename the fields when added accordingly, for ie: linkurl_1, linkdesc_1, linkurl_2, linkdesc_2, and so on.
I don't really care whether users out of order delete line(s), just as long as each array of the inputs will have their own distinct number. The main reason why I need this is because I'm having a hard time to split the textarea fields with comma(,) delimiter.
Thank you.
I found this tutorial and would like to change it to my requirements
Code:
<script>
/*
This script is identical to the above JavaScript function.
*/
var ct = 1;
function new_link()
{
ct++;
var div1 = document.createElement('div');
div1.id = ct;
// link to delete extended form elements
var delLink = '<div style="text-align:right;margin-right:65px"><a href="javascript:delIt('+ ct +')">Del</a></div>';
div1.innerHTML = document.getElementById('newlinktpl').innerHTML + delLink;
document.getElementById('newlink').appendChild(div1);
}
// function to delete the newly added set of elements
function delIt(eleId)
{
d = document;
var ele = d.getElementById(eleId);
var parentEle = d.getElementById('newlink');
parentEle.removeChild(ele);
}
</script>
<form method="post" name="test" action="test.asp">
<div id="newlink">
<div>
<table border=0>
<tr>
<td> Link URL: </td>
<td> <input type="text" name="linkurl" value="" > </td>
</tr>
<tr>
<td> Link Description: </td>
<td> <textarea name="linkdesc" cols="50" rows="5" ></textarea> </td>
</tr>
</table>
</div>
</div>
<p>
<br>
<input type="submit" name="submit1">
<input type="reset" name="reset1">
</p>
<p id="addnew">
<a href="javascript:new_link()">Add New </a>
</p>
</form>
<div id="newlinktpl" style="display:none">
<div>
<table border=0>
<tr>
<td> Link URL: </td>
<td> <input type="text" name="linkurl" value=""> </td>
</tr>
<tr>
<td> Link Description: </td>
<td> <textarea name="linkdesc" cols="50" rows="5" ></textarea> </td>
</tr>
</table>
</div>
</div>
I'm looking for a way to rename the fields when added accordingly, for ie: linkurl_1, linkdesc_1, linkurl_2, linkdesc_2, and so on.
I don't really care whether users out of order delete line(s), just as long as each array of the inputs will have their own distinct number. The main reason why I need this is because I'm having a hard time to split the textarea fields with comma(,) delimiter.
Thank you.