djs1 Posted June 16, 2011 Share Posted June 16, 2011 Hello, I'm working on a quote generator and I'm running into an issue with onChange events not firing when a text field is dynamically populated via a child window. Here's my setup: I have 3 text boxes (quantity, price, markup) that are multiplied together in order to give the total of that product. Each text box has an onChange event, that calls an external javascript file, which handles the multiplication and instantly updates the total of that product. Up to this point, everything works fine - - when I manually edit any of the 3 inputs, the total updates correctly. However, my problem is that I now have the "price" text box being dynamically populated, and when it updates it is not firing the onChange event attached to it. The text box is being filled by way of launching a child window and running the following code within it: function call_submit() { opener.document.estimator_form.item_price_1.value=document.child.prods.options[document.child.prods.selectedIndex].id self.close(); } So, as of right now, the following is happening - - I launch the child window, I select the product to add to the quote, the child window closes and the price is correctly populated within the "price" text box, BUT the total stays at zero. If I manually edit any of the fields, it then catches back up and properly updates the total. Is their any way to fire the onChange event at the time when the text field is populated from the child window? Any help would be appreciated. Thanks in advance. Quote Link to comment https://forums.phpfreaks.com/topic/239559-onchange-event-not-firing-when-input-is-dynamically-populated/ Share on other sites More sharing options...
sunfighter Posted June 16, 2011 Share Posted June 16, 2011 When you call the the call_submit() function to fill your price textbox just call the function that the onchange element would from the call_submit() function. Quote Link to comment https://forums.phpfreaks.com/topic/239559-onchange-event-not-firing-when-input-is-dynamically-populated/#findComment-1230679 Share on other sites More sharing options...
djs1 Posted June 16, 2011 Author Share Posted June 16, 2011 Thanks for the response. So my price text box contains the following event - onchange="calculator()". I took your advice and tried the following within the child window, but it still didn't trigger the onchange event. function call_submit() { opener.document.estimator_form.item_price_1.value=document.child.prods.options[document.child.prods.selectedIndex].id function calculator () { // function here } self.close(); } And within the calculator function I tried changing all instances of "document.getElementById" to "opener.document.getElementById". And like I said, neither way worked. Is this what you meant for me to do, or did I misunderstand? Quote Link to comment https://forums.phpfreaks.com/topic/239559-onchange-event-not-firing-when-input-is-dynamically-populated/#findComment-1230719 Share on other sites More sharing options...
djs1 Posted June 16, 2011 Author Share Posted June 16, 2011 Well, I finally got this working, and I figured I would post the answer, in hopes that it may be able to help someone else out there... function call_submit() { opener.document.estimator_form.item_price_1.value=document.child.prods.options[document.child.prods.selectedIndex].id window.opener.calculator(); self.close(); } Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/239559-onchange-event-not-firing-when-input-is-dynamically-populated/#findComment-1230815 Share on other sites More sharing options...
Omirion Posted June 17, 2011 Share Posted June 17, 2011 Marking the thread solved wouldn't hurt too. (bottom left) Quote Link to comment https://forums.phpfreaks.com/topic/239559-onchange-event-not-firing-when-input-is-dynamically-populated/#findComment-1230956 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.