Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Add new line to form with new name value

Status
Not open for further replies.

cumap

IS-IT--Management
Jul 9, 2007
268
US
Hello,

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.

 
Hi

In the recent thread216-1632056 and thread216-1632665 we transformed the [tt]input[/tt] [tt]name[/tt]s to arrays. That way there is no explicit numbering, but your server-side CGI library will handle them as arrays. No idea about ASP, try it. Just change every "linkurl" and "linkdesc" to "linkurl[]" and "linkdesc[]", then see what you get on server-side.

Hopefully I understand you correctly, despite that I have no idea what and why you had to split up.


Feherke.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top