Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Update Record on changed fields

Posted on 2003-11-18
4
Medium Priority
?
207 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 168 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 164 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 168 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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 …
Without even knowing it, most of us are using web applications on a daily basis.  In fact, Gmail and Yahoo email, Twitter, Facebook, and eBay are used by most of us daily—and they are web applications. We generally confuse these web applications to…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

610 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