•
•
•
•
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
![]() |
•
•
Join Date: Oct 2007
Location: England
Posts: 30
Reputation:
Rep Power: 1
Solved Threads: 0
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.
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.
•
•
Join Date: Apr 2008
Posts: 2
Reputation:
Rep Power: 0
Solved Threads: 0
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>![]() |
•
•
•
•
•
•
•
•
DaniWeb JavaScript / DHTML / AJAX Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Other Threads in the JavaScript / DHTML / AJAX Forum
- Previous Thread: javascript onclick is not working in IE7 & IE6
- Next Thread: Form reply to my e-mail


Linear Mode