There is a fairly standard method out there for checking or testing if one or more controls on your form has been changed by simply looping through the form elements and checking their state vs. the default state. ie: the following code - this.formIsDirty = function (formObj)
-
{
-
for (var i = 0; i < formObj.elements.length; i++)
-
{
-
var element = formObj.elements[i];
-
var type = element.type;
-
if (type == "checkbox" || type == "radio")
-
{
-
if (element.checked != element.defaultChecked)
-
{
-
return true;
-
}
-
}
-
else if (type == "hidden" || type == "password" || type == "text" ||
-
type == "textarea")
-
{
-
if (element.value != element.defaultValue)
-
{
-
return true;
-
}
-
}
-
else if (type == "select-one" || type == "select-multiple")
-
{
-
for (var j = 0; j < element.options.length; j++)
-
{
-
if (element.options[j].selected !=
-
element.options[j].defaultSelected)
-
{
-
return true;
-
}
-
}
-
}
-
}
-
return false;
-
};
-
That works great when your form is loaded with a value.
And I assume (if I am wrong here please correct me) that the default value/status is untouchable for updating.
This technique does not lend itself very well to a form that loads blank and is then back filled with data from an ajax call. In this scenario, it would be nice to establish a point at which the default values are set.
There is a difference between loading a form with data from the database and changing one or more of the values which have been loaded.
Is there some similar generic routine that could be used to test if one or more states/values of a form loaded from an AJAX call have been changed?
4 4836 Dormilich 8,658
Recognized Expert Moderator Expert
the only statement in this regard I found is
The accept, alt, max, min, multiple, pattern, placeholder, required, size, src, and step IDL attributes must reflect the respective content attributes of the same name. The dirName IDL attribute must reflect the dirname content attribute. The readOnly IDL attribute must reflect the readonly content attribute. The defaultChecked IDL attribute must reflect the checked content attribute. The defaultValue IDL attribute must reflect the value content attribute.
so I guess it doesn’t work with AJAX-given "default" values.
Yeah! that was the conclusion I also reached. Interesting the number of articles found on the web touting this as the way to go in handling change detection when ajax and json is the main method of communication these days.
Thanks for the followup.
Dormilich 8,658
Recognized Expert Moderator Expert
you can of course define your own property (say input.predefine d ), where you can write your default value from AJAX.
That is one way to do it. I currently have a clunky system by which I update a global flag when any control is updated on the screen. On navigation from the screen without a save I alert the user to cancel or save.
I might have been using the test of the default value if I had not gotten this advice http://bytes.com/topic/javascript/an...ld#post3128929 back on May 25 '08. From the advice I determined there was no way to detect the default value, which of course was wrong.
Your method is similar to what I am doing, but I see it may be possible to use your concept to write a generic routine that would run when the form is loaded and add the predefined property to each control, which my ajax calls could update. It may be worth writing a small article about that and posting the example of how that might be done as an alternative to the current approach. You should think about that.
Thanks as always for your great advice.
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: clarket |
last post by:
Hi,
I have a html form where all the details are saved in a MySQL database
that uses PHP to insert the data into the database.
The problem I'm having is that if people dont submit the form then the
data doesnt get saved to the database.
|
by: deko |
last post by:
I'm trying to set up a "preferences form" where users can choose from a few
different pre-defined colors. The color numbers and form names are saved in
tblColors. The below code changes the form backcolor no problem, but the colors
go back to what they were before if I close and reopen the database. How to I
save the changes? Shouldn't "DoCmd.RunCommand acCmdSave" do the trick?
For Each varF In Array("frm0", "frm1", "frm2", "frm3")...
|
by: fh1996 |
last post by:
Form.Owner and Form.Parent, what's the difference between them?
Form.ShowDialog() and Form.Show(), when to use which?
Form.Activated(), what does it mean when saying a Form is "activated"?
Thanks!
|
by: Dino M. Buljubasic |
last post by:
I'd like to check if a form is already open before opening it and if it is
not, then open it, otherwise just make it the active form.
How can I do that?
Regards,
Dino
--
|
by: astro |
last post by:
Is there a command/syntax that will force a given datagrid to submit it's
changes to it's dataset?
I know the currencymanager is responsable for this.......just can't get it
to work. I've tried;
CType(ctrl, DataGrid).BindingContext.Item(0).EndCurrentEdit()
To no effect.
| |
by: lesperancer |
last post by:
I've got a form that is opened in readonly mode and no fields can be
changed, great
but if I click on a combo box that has an _enter() event that sets a
field on my form to a value (albeit the same value it currently has),
the form becomes 'dirty'
and from that point on, I can changed any data in any field
and I checked the .allowEdit setting, and it is still false, which is
misleading me ?
|
by: gazelle04 |
last post by:
I'm trying to track data changes on my database. On form I create a procedure on Before Update event to track data changes, here it is: (It also puts the username who changes the record.
Dim ctl As Control
For Each ctl In Controls
If TypeOf ctl Is TextBox Then
If ctl.Value <> ctl.OldValue Then
Dim ans As Integer
ans = MsgBox("A record has changed." & vbcrkf + vbCrLf & _
|
by: JonBosker |
last post by:
I have a form developed in ASP.net and as such all of my controls are
server controls and do not have access to onchange events.
What I need is a javascript program to detect changes.
Here is my idea... when the page loads the program cycles through all
of the objects in the form and saves their values into a variable.
Then, when the user attempts to navigate away the program cycles
through all of the objects in the form and saves the...
|
by: The Mad Ape |
last post by:
Hi
Whenever I open a form and want to check for an existence of the form
I use the following code:
Dim frm As Form
For Each frm In Me.MdiParent.MdiChildren
If TypeOf frm Is Form17 Then
frm.Close()
End If
|
by: dirksza2009 |
last post by:
Hi,
I've made a multi user (4 end users) database in Access 2000. I've made data tables, reference tables etc which sits on a shared drive and I've made individual front ends for the end users which gives them specific views of the data.
I'd like to track all the changes made to a record which works find with the following code :
basAuditTrail:
Option Compare Database
Const cDQ As String = """"
Sub AuditTrail(frm As Form, recordid As...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |