December 21st, 2013, 09:12 PM
Get rows (<tr>) and cells (<td> or <th>) from request.form
I am building an application where the user can add or delete rows to/from an HTML table. Once they are happy, they then request that all the data get written to a database.
This is done by calling an ASP (classic) routine.
Now I want to write all the data to the database via classic ASP.
I can easily go through all the form.fieldnames in ASP.
But I'm really perplexed about how to go through all the rows of the HTML table and get all the cells.
Oh... there can be any number of rows, AND a varying number of columns (cells). Of course, there is a consistent number of cells for all rows for any execution.
How can I tell how many rows there are in the table, and how many columns (cells) in each row ?
It MUST be somewhere in the HTTPRequest, or ?????
December 23rd, 2013, 05:25 PM
Well, I figured out a way to do this..... here is the explanation for anyone who might be interested.
The ASP module needs to know all the values from the invoking form so it can do the database update.
To invoke this ASP module, I am using XMLHTTPRequest.
If you don't know what this is, or how it works, I advise you to do some research.
Fundamentally it allows you to transfer control to another module (ASP, PHP, whatever). In so doing, it will NOT create a new window/page, but will allow it to process. And in the invocation, you can indicate if you wish to WAIT till it finishes (returns something), or carry on concurrently (it can still return some value).
I use this capability quite extensively to build/construct dynamic page portions (DIVs) and then return them to the invoking routine.
Anyway, I call the database update ASP module using this capability, and wait till it is finished it's work.
But I need to get all the form fields to this module. (as per my original question)
When you invoke a module via XMLHTTPRequest, you can pass it parameters. If you invoke it with a "GET" command, the parameters are visible to the user as part of the URL and appear in the address bar. But if you invoke it with a "POST" command, the parameters are hidden from the user. Essentially this is how the "request.form" function works.
Of course, the invoked ASP module needs to know the various names being provided. But for the table rows/cells I merely created arrays of comma-separated values. For example, I created an array for each row of cells. I gave that item a name of "row" + rownumber.
Then in the ASP module, I merely looked for a field with a name that had "row" in it, then stored the value into a string, then parsed that string to remove the commas, and wind up with an array of values.
I then construct the appropriate sql statements to update the database accordingly.
It returns a message about the database being updated, which the invoking module then displays (alert) to the user. Remember it is waiting for the database update routing to finish/return.
Everything now works perfectly.
If anyone has any questions or comments, I'd be happy to respond.
December 23rd, 2013, 08:18 PM
Thanks for posting the update.
The man who doesn't read good books has no advantage over the man who can't read them.