Forum Moderators: open
We are looking at tying a javascript onchange script on each one of our text fields, and have the onchange submit the data to the MYSQL database, after each text field is completed.
Since javascript is client side and MYSQL and PHP is server side, its not straight forward.
Im sure this has been done before, and I can find bits and pieces on the web, but not an easy to understand complete solution.
Any body have some sample code, or some good references to handle javascript-php-mysql interaction
onchange of a form field. Another way would be to instantiate an XML object call (or similar). What I would probably do, if I were you, is to generate a unique ID (as a hidden value) for each form. Then submit the ID along with the name and value of the field that was changed. This way you don't need to submit the entire form each time, but can still keep track of which form data is all part of the same session.
1px iframe is the way I would do it. Easy to set up. Easy to manage.
1) if the user closes the browser session
2) if the user hits the back button
Sending the data to the database on every form entry would be overkill.
In the past I have seen this used for malicious purposes, and I don't want to trigger any popup warning messages. As all we are trying to do is save the user data, not create a popup storm, etc. ie. I want to keep it legimimate and transparent to the user.
I very rarely use javascript, as Im a server-side scripting person. Can the javascript action on back button detect or browser exit be done in modern browsers?
Use a body
onunload ... But, of course, use a check variable which is set to something; upon normal submittal the variable should be set to something else. Let the onunload function check if the variable is still set to its default value of something, and only then post the code to the iframe.