Solved

Update Record on changed fields

Posted on 2003-11-18
4
198 Views
Last Modified: 2011-09-20
Hi,
What/how is the best way of only saving changed fields to a record in a DB.
I am using Access/ASP.
Do I use javascript to only submit changed feilds or do I use use ASP to only update the DB with the changed fields.

I thought of doing it this way:-
<input type=text name=Firstname>
<input type=hidden name=FirstnameH>
<input type=text name=Lastname>
<input type=hidden name=LastnameH>

Then when I submit the form I use ASP to compare the Firstname & FirstnameH and only comit the field to the DB if they don't match. etc etc

Any ideas?

Regards
PF
0
Comment
Question by:pforeman
4 Comments
 
LVL 6

Assisted Solution

by:jarasa
jarasa earned 42 total points
ID: 9771235
Hi Pf.

As I see it it really does not matter where you do it either ways the Forms will be sent to the server and there should be the best place to check if the fields had been changed or not.

In someway what you could do is to activate the submit button once the user has made a change and if he does not made any just don't let him sumbmit the form. If you want to do that, you can do it with JavaScript checking on every field OnFocus method if the fields had changed, but you should first keep the original data from the field on variables.

....
<Script ...>
var oldField1;
....

function LoadForm() {
    oldFiled1 = Form1.field1.value;
....
}

function CheckChanges () {

if (oldField1<>Form1.field1.value) {

     Form1.send.enabled=true; // Don't remember is this is the good way to anable a button but ...
....
}
}
</Script>

<Body .... OnInit="LoadForm()">
<Form ...>
<input ..... OnFocus="CheckChanges()">
<input type="button" disabled name="send" onClick=Form1.submit()>
</Form>
</Body>
....
0
 
LVL 15

Assisted Solution

by:VincentPuglia
VincentPuglia earned 41 total points
ID: 9779896
Hi,

  You might want to consider checking the value against the field's defaultValue, thereby eliminating the need of saving original values.  
<html><head>
<script>
function doit(formObj)
{
  var isOk2Send = false;
  for (var i = 0; i < formObj.length; i++)
  {
    el = formObj.elements[i]
    if (el.type == 'text' && el.defaultValue != el.value)
      isOk2Send = true;
  }
  return isOk2Send
}
</script>
</head>
<body>
<form name="theForm" action="http://members.aol.com/grassblad" onsubmit='return doit(this)'>
<input type='text' value="a">
<input type='text' value="b">
<input type='text' value="c">
<input type="submit">
</form>
</body>
</html>

Another alternative would be to use an onblur event handler for each field that does some preliminary validation, as well as setting a flag for submission.

Vinny
 
0
 
LVL 11

Accepted Solution

by:
Zontar earned 42 total points
ID: 9790226
A good RDBMS will ignore the attempt to update fields when the value's the same.

> Form1.send.enabled=true; // Don't remember is this is the good way to anable a button but ...

Actually, that should be

document.Form1.send.disabled = false;

or

document.Form1.send.removeAttribute("disabled");

Why do you use two different ways to access the form elements in the same script?

  for (var i = 0; i < formObj.length; i++)
  {
    el = formObj.elements[i]

IMO it's better to be consistent about these things. :)
0
 
LVL 2

Author Comment

by:pforeman
ID: 10919833
Sorry forgot all about this question so I have split the points between you all.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Windows Standards for file storage. 3 19
Contact Forms for Website 6 78
Select distinct 25 81
Adding a hidden div to each row in a table 6 61
Most of the sites are being standardized with W3C Web Standards. W3C provides lot of web standard services to the web. They have the web specification, process and documentation for all the web standards. You can apply HTML, CSS and Accessibility st…
Preface This article introduces an authentication and authorization system for a website.  It is understood by the author and the project contributors that there is no such thing as a "one size fits all" system.  That being said, there is a certa…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…

914 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now