Solved

Update Record on changed fields

Posted on 2003-11-18
4
202 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
IndexedDB how to clear the DB when returning but not refreshing? 1 163
I starting with php 12 140
Problem to ToolkitScriptManager 2 77
Questions about this React unit test 4 70
What is Node.js? Node.js is a server side scripting language much like PHP or ASP but is used to implement the complete package of HTTP webserver and application framework. The difference is that Node.js’s execution engine is asynchronous and event…
I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

730 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