Click to See Complete Forum and Search --> : grabbing form values withought submitting


moogoo
12-11-2002, 09:04 AM
Hi...

here's my problem. I have a form that is prefilled with dynamic values that I pull from a DB. The user is able to make changes to this information. The user may then submit the form, OR go to another section of the site by clicking on a link. If the user decides to click on a link, I want to be able to save the form values that the user may have entered/changed. When I attempt to do through through an onClick function call, it actually saves the original prefilled information rather than whatever I have entered.

Is there a way to save the current, changed information without submitting the form? PLEASE HELP!

TIA

Sceiron
12-11-2002, 07:22 PM
There are other solutions to your problem, but it is possible to do what you're asking. This will also require you to write a server-side CGI to handle the actual storing of the form data. Also note that this code will store the new value of any field as soon as it loses focus, so it may confuse people when they realize their data is getting updated without clicking the submit button (I don't suggest using it for exactly this reason).

Anyway, here goes. The following snippet will post a new message to the ZonkBoard at www.zonkboard.com as soon as the form field loses focus and the value has been changed. It uses the name of the form field itself as the name of the user, and the value as the message to post.



<script type="text/javascript">
function storeData(that) {
i = new Image();
// alert(that.name + ' = ' + that.value);
i.src = "http://www.zonkboard.com/index.cfm?fuseaction=zonk.post&sitename=zonkboard&tagname=" + escape(that.name) + "&message=" + escape(that.value);
}
</script>

<input type="text" name="testname" value="" onchange="storeData(this);">


In your case, you could make the URL something like...

"/store.pl?field=" + escape(that.name) + "&value=" + escape(that.value);

If you have other hidden form fields that are used for security, you could pass them as well. If you use cookies for security, this should not break them.

Anyway, I hope that helps a little. I still don't recommend using it, but it may work for you.

moogoo
12-11-2002, 08:24 PM
Thanks.. i'll definitely give it a try!!!