Solved

Update Record on changed fields

Posted on 2003-11-18
4
197 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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

Preface This is the third article about the EE Collaborative Login Project. A Better Website Login System (http://www.experts-exchange.com/A_2902.html) introduces the Login System and shows how to implement a login page. The EE Collaborative Logi…
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 …
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

707 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

19 Experts available now in Live!

Get 1:1 Help Now