By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,615 Members | 1,961 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,615 IT Pros & Developers. It's quick & easy.

Dynamically attach a property value to input element

P: n/a
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
Share this Question
Share on Google+
4 Replies


P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.