User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the JavaScript / DHTML / AJAX section within the Web Development category of DaniWeb, a massive community of 403,396 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 4,685 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our JavaScript / DHTML / AJAX advertiser: Lunarpages Web Hosting
Views: 1568 | Replies: 1
Reply
Join Date: Oct 2007
Location: England
Posts: 30
Reputation: mortalex is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
mortalex mortalex is offline Offline
Light Poster

Dynamically add rows to a form

  #1  
Apr 9th, 2008
Hey,

I have a problem that i have been working on for too long, how can i add rows and remove rows from a form dynamically using javascript?

What i need is two buttons, one to add a row and the other to remove the row. How would i do this?

In this form i have, on one line, a couple of text boxes, is this possible to achieve, on an HTML form not an HTML table

Cheers.
Last edited by mortalex : Apr 9th, 2008 at 5:09 pm.
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Apr 2008
Posts: 2
Reputation: aheman is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
aheman aheman is offline Offline
Newbie Poster

Re: Dynamically add rows to a form

  #2  
Apr 10th, 2008
Without the table, I'm not certain there's a solution. The table wouldn't need to be particularly complicated.
<form>
     <table name="mytable" id="mytable">
          <tr>
               <td><input type="button" value="Add Row" onclick="addrow('mytable')"></td>
               <td><input type="button" value="Subtract Row" onclick="subtractrow('mytable')"></td></tr>
     </table>
</form>

<script>
function addrow(el){
	usertbl = $(el);
	srow = usertbl.insertRow(numRows(el)+1);
	cell1 = srow.insertCell(0);
        
        element1 = document.createElement('input');
        element1.setAttribute('type','text');
        cell1.appendChild(element1);
}
function subtractrow(el){
	if(numRows(el)!=0){
		usertbl = $(el);
		srow = usertbl.deleteRow(numRows(el));
	}
}
</script>
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb JavaScript / DHTML / AJAX Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Other Threads in the JavaScript / DHTML / AJAX Forum

All times are GMT -4. The time now is 9:39 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC