• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 208
  • Last Modified:

Update Record on changed fields

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
pforeman
Asked:
pforeman
3 Solutions
 
jarasaCommented:
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
 
VincentPugliaCommented:
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
 
ZontarCommented:
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
 
pforemanAuthor Commented:
Sorry forgot all about this question so I have split the points between you all.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now