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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dynamic Tables 1

Status
Not open for further replies.

Mighty

Programmer
Feb 22, 2001
1,682
US
Does anyone know how to add rows to a table dynamically. Or can it even be done.

i.e. when the user clicks a button another row will be added to a table.

I have tried generating a table of 50 rows and making only one visible. Then when the button is clicked, I make another row visible. The only problem with this is that the browser reserves some space for the rows. Mise Le Meas,

Mighty :)
 
Im not sure if I understood you right but do you mean that when you make the rows invisible they take up the space on the page but are not visible.

If so I guess you are using the visibility property??

Have you tried using the display property? If not i think you can do what you want using it.

Just make the first rows property display: and the other rows display:none then on click change the property of the row object ie <span id=&quot;row2&quot;> <tr> </span>
to display:

so function would look like

function changeDisplay () {

docuument.all.row2.style.display:none

}

hope this helps?


 
NikP,

Thanks for the pointer but I am already using display.

The visibility style property reserves all the space when the rows are not visible. However, while the display property does not reserve all the space, the rows still take up some space (alot more in Netscape than in IE).

I was hoping to be able to add rows dynamically rather than just make them visible. Mise Le Meas,

Mighty :)
 
Mighty,
I'm not sure I understand what you're really trying to do. When the user hits the button, do you want to make the next row of data visible in the form? Or do you want to add another row of data to the underlying table(s)?

If the latter is what you want to do, here is the code:
Code:
Dim rst as Recordset
Dim dbs as Database
Set dbs = CurrentDb()

'Define the recordset &quot;TableName&quot; can be replaced with a SQL statement
Set rst = dbs.OpenRecordset(&quot;TableName&quot;)

'Add a new record
rst.AddNew

'Define the fields
rst.[Field1] = yourdata1
rst.[Field2] = yourdata2

'Update the recordset and close it
rst.Update
rst.Close

'Requery the form to show the new data
Me.Requery

'Release the memory from the rst and dbs vars
Set rst = Nothing
Set dbs = Nothing

Let me know if that doesn't answer your question Jonathan
________________________________________
It is not fair to ask of others what you are unwilling to do yourself.
-Eleanor Roosevelt
 
OK, maybe I should make myself clearer.

I have a product order form which has 5 input fields - one select and four text boxes. When the page loads there is one row of input fields available. I also have two buttons - one is to &quot;Submit Order&quot; and the other is to &quot;Add Another Product&quot;. When the user clicks &quot;Add Another Product&quot;, I want to be able to display another row of input fields below the first row (but above the buttons) - without going back to the server.

At the moment, when the page loads initially, I generate 50 rows but only one is visible. When the user clicks &quot;Add another product&quot;, I make another row visible. However, as I said before, space is still reserved for the rows - a lot more in Netscape than in IE5.

Is there a better way to do this?? Mise Le Meas,

Mighty :)
 
You could try using a named <div> tag around the table and then set the innerHTML property, as in the following function...

function display(name, str)
{
if (IE4) {
window.document.all [name].innerHTML = str;
} else if (NS4) {
with(document ['&quot;' + name + '&quot;'].document)
{
open();
write(str);
close();
}
}
}

You'll have to keep track of the current content and then add dynamically to it.

Hope this helps...
allow thyself to be the spark that lights the fire
haslo@haslo.ch - www.haslo.ch​
 
I forgot: There may be problems if you use some <input>s - you'll have to keep track of all those too, and I think you'll have to back them up every time you change the HTML code. Did not test it, just thinking...
allow thyself to be the spark that lights the fire
haslo@haslo.ch - www.haslo.ch​
 
Haslo,

IN the parameters in the above function, I am presuming that name is the name of the DIV - is this correct? Mise Le Meas,

Mighty :)
 
Yes, just so.
I would use Arrays for holding the momentaneous form data, then you'll have to name the <input> fields dynamically (via the Javascript creating the str parameter) and afterwards read them into the array the very same way (via dynamic naming).

I don't know if there's an easier way to do it...
allow thyself to be the spark that lights the fire
haslo@haslo.ch - www.haslo.ch​
 
Haslo,

I have been working through your suggestions. I haven't tried it in Netscape yet and I have had to change some of it slightly to work in IE5 but it seems like things are going to work out.

Cheers. Mise Le Meas,

Mighty :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top