Forum: Rails Spinoffs (closed, excessive spam) Fire Native Browser Event

3125c77bab66fa37dfdbe78eb29339b6?d=identicon&s=25 Dean (Guest)
on 2008-06-18 02:35
(Received via mailing list)
Hi Prototype people

Is there a good way to fire the browser's native onchange event?
Here's my situation.

I am using prototype and lowpro.  I have a text input box and some
divs.  When the user mousedown's on one div, numbers in the input box
start changing.  onmouseup, the numbers stop changing.  I would also
like to alert the form that one of its inputs has changed.

Here are some simplified snippets of the lowpro Behavior class I
created to do the heavy lifting:

doIncrement : function()
{  newVal = 1 * this.inputBox.value;
   newVal = newVal + 0.1;
   newVal = newVal.toFixed(1);
   this.inputBox.value = newVal;
   this.timeoutEvent = setTimeout( this.doIncrement.bind(this), 150 );

onmousedown : function(evt)
{  this.doIncrement();

onmouseup : function(evt)
{  clearTimeout( this.timeoutEvent );

Since I explicitly set the input's value with this.input.value =
newVal; the onchange event does not trigger (in Firefox for

I am sprinkling these input into different forms that I need to inform
of changes, so calling a custom function in onmouseup() won't do the

It appears that jQuery can do it, and from what I gather in its
source, they eventually just do elem["change"](); but that throws an
"is not defined" error.

Any suggestions?

F1fcf834ddad415f60d29c87cc10d4d4?d=identicon&s=25 kangax (Guest)
on 2008-06-18 03:31
(Received via mailing list)
Custom events could help:

// use custom event as a proxy
$(someInput).observe('change', function()
{'content:changed') });
doIncrement : function() {
   this.inputBox.setValue((parseFloat($F(this.inputBox)) +
   // fire custom event'content:changed');
   this.timeoutEvent = setTimeout( this.doIncrement.bind(this), 150 );
// observe custom "content:changed" instead of "change"
$(somInput).observe('content:changed', function(e) {
  // do stuff

You could also take a look at Event#simulate

- kangax
3125c77bab66fa37dfdbe78eb29339b6?d=identicon&s=25 Dean (Guest)
on 2008-06-18 05:01
(Received via mailing list)
On Jun 17, 8:30 pm, kangax <> wrote:
> Custom events could help:
> // use custom event as a proxy

This is what I ended up doing.  I will keep an eye out for

Thanks for the help.

This topic is locked and can not be replied to.