473,394 Members | 1,806 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Dynamically attach a property value to input element

I want to implement a good Persistent State checking feature, this
feature should show the user the Save button only when there are
changes to save, if there are no changes, the button will be hidden.

I thought to do it, this way:

When the page is first loaded, I'll save the values of each of the
input elements and each time an input is modified I'll compare the
previously saved value with the last entered by the user, this way if
the user deletes and wrote the same value, it'll recognize that there's
no need to save.

Now, I want to implement it the little as possible, so I thought to
save the initial value in the same input element, I haven't found an
inout's property where I can store the value...

Is it possible to dinamically add a property to the input where I could
store my value?

Best Regards
Fabio Cavassini

Jan 23 '06 #1
4 1884
Fabio Cavassini wrote:
I want to implement a good Persistent State checking feature, this
feature should show the user the Save button only when there are
changes to save, if there are no changes, the button will be hidden.
.... snip ... Is it possible to dinamically add a property to the input where I could
store my value?


Most input fields already have such a property.

For checkbox & radio you want the defaultChecked property, for password,
textarea & text you want defaultValue. hidden fields may have originalValue
(but only I think IE, Mozilla doesn't have an equivalent). Single entry
select boxes have defaultSelect, but you cannot distinguish between
starting with nothing selected and starting with the first element
selected. For multiple select elements defaultSelected works fine.

See
http://codespeak.net/svn/kupu/trunk/...eforeunload.js
for some code which installs an onbeforeunload handler to warn the user
against leaving a page without saving changes. You could base your own code
on that.

I think it may be quite tricky though ensuring that the button is enabled
at exactly the right time especially if, for example, you allow submitting
the form by pressing return: changes to the save button state would have to
be instantaneous, not waiting for onblur from fields.
Jan 23 '06 #2
On 2006-01-23, Fabio Cavassini <ca********@gmail.com> wrote:
When the page is first loaded, I'll save the values of each of the
input elements and each time an input is modified I'll compare the
previously saved value with the last entered by the user, this way if
the user deletes and wrote the same value, it'll recognize that there's
no need to save.


You needn't save them. Every field element had a defaultValue (or
defaultChecked etc) property that stores its original value, (hmm
that seems to answer the rest of your post too). good luck.

Bye.
Jasen
Jan 24 '06 #3
The problem is.... that I'm using Ajax to load Dinamically the values,
here it's how it works:

I have a parent page with a Tab selector, when user selects different
tabs, different html is loaded on a DIV element
This html contains the input fields...that are loaded without data on
it, after loaded the page a JavaScript function loads the data....

Is it possible to change defaultValue, defaultSelect, defaultChecked
after the page has loaded?

Best Regards
Fabio Cavassini

Jan 24 '06 #4
On 2006-01-24, Fabio Cavassini <ca********@gmail.com> wrote:
The problem is.... that I'm using Ajax to load Dinamically the values,
here it's how it works:

I have a parent page with a Tab selector, when user selects different
tabs, different html is loaded on a DIV element
This html contains the input fields...that are loaded without data on
it, after loaded the page a JavaScript function loads the data....

Is it possible to change defaultValue, defaultSelect, defaultChecked
after the page has loaded?


yes, but changing them won't have a visible effect until the form is reset.
If you want to load values you'll need to (also) modify value, selected,
checked.

--

Bye.
Jasen
Jan 25 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Eric | last post by:
How can I dynamically assign an event to an element? I have tried : (myelement is a text input) document.getElementById('myelement').onKeyUp = "myfnc(param1,param2,param3)"; ...
4
by: RobG | last post by:
I have a function whose parameter is a reference the element that called it: function someFunction(el) { ... } The function is assigned to the onclick event of some elements in the HTML...
2
by: Sethos | last post by:
I am sure that this has been covered, hashed, and rehashed, but a search on the group did not produce the answer, so forgive me if this seems like a "newbie" type question... Besically, I have a...
1
by: vj | last post by:
How i can populate all fileds dynamically in jsp page based on contents found in xml file? I have written jsp servlets and java class file. i transferred automatic data from jsp to servlet then to...
0
by: vijendra | last post by:
How i can populate all fileds dynamically in jsp page based on contents found in xml file?I have written jsp servlets and java class file. i transferred automatic data from jsp to servlet then to...
5
by: J | last post by:
I am having problems dynamically adding more than one event handler to an input. I have tried the Javascript included at the bottom. The lines inp.attachEvent('onkeyup',...
1
by: chrisdr | last post by:
I found this code in a previous post but I am not able to get this to work for me... I am trying to dynamically change an element's type from textbox to textarea with an event. Actually in my code...
2
by: robert112 | last post by:
This is quite a hard one guys. ***Some necessary back ground Info*** I have an asp.net 1.1 application that uses a WYSIWYG to return some html created by the user in the admin section of the...
1
by: sindhu | last post by:
Hello, I am able to attach event to dynamically created element.as shown below. for(var i=0;i<10;i++) {for(var j=0;j<15;j++) { var div=document.createElement('div'); ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
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,...
0
Oralloy
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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...
0
tracyyun
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.