Link to home
Start Free TrialLog in
Avatar of universalglove
universalgloveFlag for United States of America

asked on

VBScript and Selecting Specific Uploaded Form Data

Is there an efficient way to select specific, associated groups of fields from an uploaded form and only those fields, using VBScript and classic ASP?

I have a listing of different entities pulled from a database, each consisting of a title, body content, link, etc. - @ 8 fields for each entity. All entities are pulled and displayed at once in a long list; are all contained within the same form; and can all be edited before submitting and saving to the database.
I would like to be able, upon uploading the form data, to select only particular groups of form fields marked as changed. I'm currently seeing if a checkbox checked onChange via Javascript can denote a set of changed fields. And I wonder if fieldsets can be used server-side to select out groups of form fields, or if there's some other such container or selection method available to select out and resave to the database only the entities that have been modified.
This is my goal anyway.

I realize that there are methods in Javascript to accomplish this sort of thing now (in correlation with .NET?), and that ASP.NET and C#, etc would be superior for this type of application, but those are not an option because I can't take the time to learn that for this project and rewrite the entire thing.
So, I'm not looking for the kinds of answers that C# is better or Javascript is the way to go.

Is it perhaps more efficient in the end, considering time spent programming and usage of server-processing power, to simply send all fields to the database for update?
I could pare the amount of data down to an average of 16-32 entities worked with each day; but currently looking at holding a bit more history, which could mean anywhere from 100-225+ entities.
Given that I might be pulling that much out of the database, will it make much difference if I simply rewrite that much back into the database?

Thank you in advance for any assistance.
Avatar of Scott Fell
Scott Fell
Flag of United States of America image

Are you getting hundreds of updates every minute?  I know it is good to be as efficient as possible, but also consider  how much effort if it is the type of site where you maybe get a hundred updates if that through out the day rather then multiple times each second.

First, can you post a sample of your form and data.  Maybe there is some efficiencies in just that part.  

Otherwise, if you want to make sure you update only what needs updating, I would go with the checkbox "Approve this update" and only update fields that have the check box.  However, this could be cumbersome to users.

If you are going to compare data, I would do that using javascript where you place the data into a hidden field or div or some other container. Lets give this the ID, field_1_original, field_2_original...  Then using javascript compare if the data in the form field matches or does not match what is in the field_1_orginal.  If it does not match, then using javascript, update another hidden form field field_1_updateflag to 1.   Set field_1_updateflag to 0 as the page loads.  Then when the update button is hit on the form, you can loop through and only update field_1 if field_1_updateflag is set to 1 and not 0.
Avatar of universalglove


It may be that I'm being hypersensitive to efficiency, because this form would only be in use 2-3 times a day, updating those 16-32 records several (2-10) times.

I considered dynamically creating form fields on the client-side to send for update; and maybe even sending them to a separate page dynamically so I wouldn't have to reload the page.

1 question I still have about using a method like the Javascript you're suggesting, padas:
How can I associate each set of fields for an entity with the record in the database they go to? e.g. Entity1 consists of Fields: A,B,C,etc; Entity2 consists of Fields: A,B,C,etc; and so on.
If all Fields A get changed, Record1 for Entity1 has to get its correct corresponding Field A updated to it.
This would still require separate SQL statements for each, correct? (I think that's what I needed to do anyway, using an en masse method.)

Maybe it would be more helpful if I did provide a sample of the form.
Give me a moment to genericize it.
<form action="<%= strThisPagesName %>" method="post" enctype="multipart/form-data" id="Listing" name="Listing" onSubmit="">
<% for each arrData in arrListingData %>
	<fieldset id="<%= arrData("ListingID") %>" class="listing">
		<input type="hidden" id="ListingID<%= arrData("ListingID") %>" name="ListingID" value="<%= arrData("ListingID") %>" />
		<input type="hidden" id="MemberID<%= arrData("ListingID") %>" name="MemberID" value="<%= arrData("MemberID") %>" />
		<input type="checkbox" name="changedItems" class="listing-selector" value="<%= arrData("ListingID") %>" />
		<div class="listing-header">
			<span class="listing-metadata listing-title"><a href="<%= arrData("ListingURL") %>" target="_blank"><%= arrData("ListingTitle") %>"</a></span>
			<span class="listing-metadata listing-blogname"><a href="<%= arrData("BlogURL") %>" target="_blank"><%= arrData("BlogTitle") %></a></span>
			<br />
			by <span class="listing-metadata listing-author"><% Response.Write arrData("MemberFirstName") & "nbsp;" & arrData("MemberLastName") %></span>
			on <span class="listing-metadata listing-date"><%= arrData("ListingDate") %></span>
			<div class="listing-controls">
				<label for="ListingApproved<%= arrData("ListingID") %>" class="listing-metadata listing-label">Approve?</label>&nbsp;<input type="checkbox" id="ListingApproved<%= arrData("ListingID") %>" name="ListingApproved<%= arrData("ListingID") %>" class="control-checkbx listing-approve" value="<%= arrData("ListingID") %>" <% if arrData("ListingApproved") = "true" then Response.Write "checked=""checked""" end if %> />
		<div class="listing-body">
			<input type="text" id="ListingTitle<%= arrData("ListingID") %>" name="ListingTitle<%= arrData("ListingID") %>" class="listing-title-txtbx" value="<%= arrData("ListingTitle") %>" size="50" maxlength="256" />
			<div class="listing-content">
				<textarea id="ListingContent-<%= arrData("ListingID") %>" name="ListingContent<%= arrData("ListingID") %>" class="listing-content-area">
					<%= arrData("ListingContent") %>
				<input type="hidden" id="ListingImgURL<%= arrData("ListingID") %>" name="ListingImgURL<%= arrData("ListingID") %>" value="<%= arrData("ListingImgURL") %>" />
				<p id="SelectedImg<%= arrData("ListingID") %>">URL of the currently selected image: <span><%= arrData("ListingImgURL") %></span></p>
		<a href="#" class="listing-display">[+] Expand this listing</a>
	</fieldset><!-- #<%= arrData("ListingID") %> .listing -->
<% next %>

Open in new window

Avatar of Scott Fell
Scott Fell
Flag of United States of America image

Link to home
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Ok, we posted at the same time.  You used an array instead of a recordset but you can see the idea is the same.    I do think you are better off to have one form for each listing and just update the entire listing.   You can still use your array to write out the same amount of data, just put the for/next before and after the form tags so you get multiple forms.  What happens if you get 30 listings on a page?  

One problem I can see with matching exact fields as I first described is if you are using a wysiwyg in a text box, it may make changes on loading even though the data did not change.  But you for sure want to do any matching client side otherwise it can take a long time to match all that up server side and you are trying to speed things up.

The main thing is to identify the record for each field.  I think it will be easier with one form for each...
I can run with the "1 form for each" method, and just make sure users know to always hit save after editing each entry...

Or, would sending the page send all forms, and I can then access each form separately server-side, checking for "checked" in the changedItems checkbox before bothering to save the form? (I've only ever worked with pages that include 1 form.)

If so, this is sounding even better (and probably rather obvious)...! Oh well, live and learn.

Also, I am planning on inserting tinyMCE instances into each textarea as they are clicked on and then removing them as a listing is collapsed. So there will be a WYSIWYG working on the data for each content, but I don't know if it matters that I differentiate whether any changes happened.
I'm figuring so long as a user expanded a listing and clicked in something, it needs saved. So if it's a WYSIWYG editor causing that, too... meh.
Just wanting to drop a not that I'm trying to get back to this to do some testing first before actually selecting an answer (plus Thanksgiving break, and illness and such getting in the way).
What would be easy for people to understand is to have each item become a separate form.   When you click on the  text, the wysiwyg shows up for that div.   It is really the same as have a "save" button for each item but to the user, only the one area looks editable.  Here is the example with CKEditor.
I still need to be able (someday; I can always dream) to be able to get back to coding and finalizing the project and physically trying out the options.

Regardless, this is the basic gist of what I needed - tells me where I was heading is possible, but also tells me about another option and how that other option may be better.

Thanks for your help with this, padas.