I have a table with 3 rows and 2 columns. I would like on page load to only have one row visible with the bottom two rows hidden. I would like to have an "add" button on the bottom most visible row. When you click the "add" button it adds a row to the bottom and moves the add button to the bottom row. I would also like remove buttons on each row to hide that particular row. The remove button works so that any row you remove it shifts the rows up and adds an "add" button to the bottom most row.
Having only the first row visible on load is easy using:
Expand|Select|Wrap|Line Numbers
- style="display: none;"
The problem I am having is getting the "add" button to work properly. I was trying to do it using a hide/show script and combining them. When you click the button it "shows" row 2, "shows" add button on row 2 and "hides" add button on row 1. Doing it this way means I would have to use hide show functions on the remove button to get the "add" buttons to reappear. Working through it I found I was writing myself in circles using the add/show functions and it always would get out of sync.
How can I accomplish this. I have seen this kind of functionality before but cant find a website now that uses it. I am thinking I might need a smarter javascript then a simple hide/show.
The javascript i am using for the hide/show is (I know it could be a lot simpler by using something besides an if/else statement. I am not a javacripter and this is the first thing that I got to work, but perhaps someone could point me in the right direction for that as well.)
Expand|Select|Wrap|Line Numbers
- function showmb(e){
- if (e.style.display == "none"){
- e.style.display = "";
- }
- else{
- e.style.display = "";
- }
- }
- function hidemb(e){
- if (e.style.display == ""){
- e.style.display = "none";
- }
- else{
- e.style.display = "none";
- }
- }
<EDIT> Edited for claritys sake.