0

I have a web page that includes child forms on it. Looks like this:

parent form area at the top with tab1, tab2, tab3
In the middle of the page I have an iframe loading a child form (a grid)

The user can change a value on the child grid but if they click on another tab (located in the parent form) I first want to ask them if they want to switch to the other tab without saving (in which case I reset the grid value back to what it was) or if they want to stay where they are so they can click save to save their changes.

There is a click event on the tab in the Parent form and I've also added a click event for the tab in the child form. I want to handle the child event FIRST so that I can verify what the user wants to do. The problem is that the parent form event handler happens first then the child event handler happens.

How can I do this so that before executing the tab's event on the parent I first execute the child form event?

Thanks in advance!

johnr2000
  • 1
  • 2
  • Why is this using an iframe? That almost certainly makes this more complicated. – Barmar Jun 08 '18 at 00:26
  • You need to post your code. Normally events on child elements are triggered first, and they can use `event.stopPropagation()` to prevent the parent event from being triggered, because events bubble out from the deepest elements. – Barmar Jun 08 '18 at 00:37
  • But maybe the problem is because of the iframe -- the two documents are treated independently, so they each receive the event regardless of bubbling. – Barmar Jun 08 '18 at 00:38
  • Yes, I think you are correct that the two documents are treated independently. I've tried putting stopPropagation in the first event handler and it didn't stop the second event handler. If I can figure out how to have one event occur before the other AND be able to cancel the other one from happening that would be great. And also, why wouldn't I use an iframe? It's a separate form (a grid) loaded on a tab based web page. I have a web page with 4 tabs that loads separate pages. If there's a better and newer way to do it send me a link. – johnr2000 Jun 08 '18 at 00:56
  • Back to my original question: why are you using an iframe? Just use a DIV and you should be OK. – Barmar Jun 08 '18 at 00:57
  • Iframes are for unrelated documents, they normally don't need to interact with each other. – Barmar Jun 08 '18 at 00:58
  • See https://stackoverflow.com/questions/152975/how-do-i-detect-a-click-outside-an-element for how to detect a click outside the `iframe` element, so that the click on the iframe won't be handled by the parent document. – Barmar Jun 08 '18 at 00:59

0 Answers0