Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Equivilent IE "onpropertychange" event in firefox? 1

Status
Not open for further replies.

smsinger3

Programmer
Oct 5, 2000
192
US
Hello,

I'm converting an IE only page to be cross browser compliant (finally!). I'm running into one problem which I don't know of a graceful way to get around. I have a hidden text field which I attach a "onpropertyhchange" event. When the page loads, I attach several functions to that event.

Later, typically after an AJAX call, I simply update the value in the hidden text so the "onpropertychange" event fires and all the functions are run.

My problem is that the "onpropertychange" event is only for IE.

Do you have any ideas to provide the same functionality to trigger an event through a hidden text field?

Thanks in advance for your help!
 
You could go with normal text inputs, have an onchange, and blur after setting the value.

Make sure the text boxes are hidden using CSS:

Code:
.hiddenText {
   position: absolute;
   left: -10000px;
   top: -10000px;
   width: 1px;
   height: 1px;
   overflow: hidden;
}

...

<input type="text" class="hiddenText" value="123" onchange="someFunc(this);" />

Hope this helps,
Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
If I am understanding your question correctly, I had a similar issue come up in a project where I needed to fire the onChange event on a textbox after I changed the value through javascript. Heres a code snippet that fires the onChange event of a text box. Note, I've only tested on Firefox 2.X and IE 7.
Code:
// Fire the onchange event of the textbox we just changed to update date in DB
// NOTE: IE and FireFox handle dispatching events differenly
var targetTxtBox = document.getElementById('sometxtbox');
if(targetTxtBox.fireEvent) { // IE Way
    targetTxtBox.fireEvent('onchange');
} else if(document.createEvent) { // Firefox Way
    var evt = document.createEvent('HTMLEvents');
    evt.initEvent('change', true, true);
    targetTxtBox.dispatchEvent(evt);
}
 
Thanks to both of you! I ended up using yngjzy12's method because it fit better to what I was doing.
 
You can use DOMAttrModified from firefox and it works perfectly fine. I'm using it to let me know when a hidden field value changes. Here's my code I'm using in a script control:

Code:
this._onCCCHandler = Function.createDelegate(this, this._onCCC);

//pHdnFld is the hidden field I want to track changes for
var pHdnFld = window[this.get_AAAA().get_BBB()].GetHiddenField();

if (navigator.appName.indexOf("Explorer") > -1)
      $addHandler(pHdnFld, 'propertychange', this._onCCCHandler); //IE
else
      pHdnFld.addEventListener('DOMAttrModified', this._CCCHandler, false); //Firefox

Let me know if this helps anyone
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top