/    Sign up×
Community /Pin to ProfileBookmark

See both Old and New text in OnChange handler?

Is it possible to somehow get at what USED TO BE in a text area? (possibly from onChange event)

When Javascript is deciding to fire the onChange event of a TextArea element, it obviously has access to the original (unedited) text as well as the new text to see if it is different. Is the old text it compares available once the event is fired?

Specifically, I’m trying to let multiple users edit fields in a database. Currently, I show them the field in a TextArea and in the onChange event handler I call a webservice to update the DB. The webservice does it’s best to merge edits from multiple users and append to (rather than overwrite) what other users have done. The webservice could use some more info to do it’s job better. Specifically, if it knew not just what the user has in the field after editing (the .value or .innerHTML when in the onChange event handler) but what they saw before editing, it could then try to determine what edits this user is trying to make. By comparing Old and New, the web service could isolate only the things this user was trying to change and make those updates without also re-asserting the original value of text they didn’t change (so probably didn’t care about).

Is this possible or does JavaScript keep the goods for itself, discarding the old text as soon as it has made it’s decision to fire the onChange event?

Thanks

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@SyCoFeb 26.2008 — If this is an edit, then you're posting the content of a table field to the textarea, right? You could just also post if to a hidden form element too and submit it along with the new for comparison.
Copy linkTweet thisAlerts:
@CefuauthorFeb 27.2008 — Well it's not the traditional multi-step edit. I don't have the data in a table, copy it out to an area for editing then commit the edits. My table (an ASP:dataGrid) actually has a final column (this is for user comments) that is always a TextArea. So the text doesn't get copied to the TextArea except during databinding.

I could, of course, have javascript play with the DOM elements to create me copies then use them in the submit. I was hoping to avoid that effort. Obviously, the browser's javascript engine is already keeping original and new to make the fire-onChange-or-not decision so I was just hoping to be lazy and capitalize on that. I'm not at all surprised, however, if no one thought to make both sets of text available outside of the engine code.... I was just hoping.
×

Success!

Help @Cefu spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...