tags:

views:

18

answers:

1

Hello

I have this problem when I do an ajaxrequest that I lose my onchange events from my inputfields. Well I have done this function that would reinit the events to those inputs but Im not sure if that is the best way to do it..

A: 

The problem sounds as if you are replacing the DOM elements after the AJAX load - this also 'overwrites' their event handlers as they are bound to the DOM objects you replace. You have one of 3 solutions:

1) Don't replace any form DOM elements you have event handlers bound to.

2) Re-bind the event handlers after you have replace the DOM elements.

3) Use jQuery's .live() method of method binding - this means that it will not only bind the events to the elements matched by your selector, but it will continue to do so for new elements created afterward which match the selector too. I would expect this to have some sort of performance hit in the browser however, and depending on the selector used it could have undesirable effects.

Geoff Adams