Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > Watch for form element value change

Reply
Thread Tools

Watch for form element value change

 
 
VA
Guest
Posts: n/a
 
      12-24-2005
Mozilla-based browsers have watch and unwatch methods to detect change
in value of form elements (or any Javascript variables really). IE
doesn't support this.

Is there a a reliable cross-browser way alternative to this? Something
that will let me detect a change in value for a form element and
trigger my own callback function upon change?

Hopefully, something that is generic enough to be called as
"MyWatch(element)"!

Thanks for any help or pointers.

 
Reply With Quote
 
 
 
 
Michael Winter
Guest
Posts: n/a
 
      12-24-2005
On 24/12/2005 18:39, VA wrote:

> Mozilla-based browsers have watch and unwatch methods to detect
> change in value of form elements (or any Javascript variables
> really). IE doesn't support this.


Nor do most browsers.

> Is there a a reliable cross-browser way alternative to this?


The change event?

> Something that will let me detect a change in value for a form
> element and trigger my own callback function upon change?


The change event?

> Hopefully, something that is generic enough to be called as
> "MyWatch(element)"!


A function could be written to attach a predefined listener to a given
element. For instance:

function myListener() {
/* Do stuff here, using this operator to refer to element. */
}

function watchControl(ref) {
ref.onchange = myListener;
}

Mike

--
Michael Winter
Prefix subject with [News] before replying by e-mail.
 
Reply With Quote
 
 
 
 
VA
Guest
Posts: n/a
 
      12-24-2005
Michael: Yes, I am aware of the onChange event but that would be fired
only when the user manually enters the field, changes its value and
steps out of it.

I am interested in firing my own callback function whenever the *value*
of the item changes, regardless of how it is changed. Either manually
by the user or by some other function by doing, for instance,
document.getElementById('myelement').value="newval ue"

[The Mozilla "watch" method does exactly this which is why I mentioned
it]

Help? Thanks.

 
Reply With Quote
 
Martin Honnen
Guest
Posts: n/a
 
      12-25-2005


VA wrote:


> I am interested in firing my own callback function whenever the *value*
> of the item changes, regardless of how it is changed.


IE in its DOM has onpropertychange as an event handler to be fired if
properties of a DOM element are changed:
<http://msdn.microsoft.com/library/default.asp?url=/workshop/author/dhtml/reference/events/onpropertychange.asp>
It will be fired when various properties are changed, to find out
whether the value property has been changed you then need to check
event.propertyName

--

Martin Honnen
http://JavaScript.FAQTs.com/
 
Reply With Quote
 
Michael Winter
Guest
Posts: n/a
 
      12-26-2005
On 24/12/2005 23:52, VA wrote:

[snip]

> Either manually by the user


Use the change event here,

> or by some other function by doing, for instance,
> document.getElementById('myelement').value="newval ue"


and call the listener here yourself. I admit that it's not a very nice
solution, but it's about as cross-browser as you're going to get.

[snip]

Mike

--
Michael Winter
Prefix subject with [News] before replying by e-mail.
 
Reply With Quote
 
VA
Guest
Posts: n/a
 
      12-26-2005
Michael Winter wrote:
> > or by some other function by doing, for instance,
> > document.getElementById('myelement').value="newval ue"

>
> and call the listener here yourself


But that's the whole point. The value of the item is changed in many
different places by many different scripts, having to hunt down each
instance of this change and manually calling the onchange listener is
not feasible. Hence, my quest to find an automated way to do this
regardless of how/where the value is changed.

onPropertyChange sounds good, but it is IE-only and even there it
doesn't quite work properly. The example given on that MSDN page Martin
pointed me to doesn't work. It throws JS errors like (oProp not
defined, oSelect is not an object and stuff).

Looks like there is no good cross-browser solution to this problem.

Thanks.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Move value from one form element to another, hidden element viaJavaScript OccasionalFlyer Javascript 6 07-29-2009 03:33 AM
Re: Swiss Watch International Limited Edition Moon Phase IndicatorMen's Watch A9242.S.S.A1 PinkFloyd43 Digital Photography 1 08-22-2008 01:04 PM
how to Update/insert an xml element's text----> (<element>text</element>) HANM XML 2 01-29-2008 03:31 PM
moving from form element to form element Rod Snyder ASP .Net 1 05-29-2004 01:55 PM
how to change the value of a hidden form value on submit Matt Herson Javascript 8 09-30-2003 05:18 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57