Jump to content

onChange Event Not Firing when Input is Dynamically Populated


Recommended Posts

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.

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?

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!

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.