O
O
OculusDaemon2018-02-23 00:33:11
JavaScript
OculusDaemon, 2018-02-23 00:33:11

How to call the calculator separately from the modal window?

Need help initializing a modal window.
There is a site on which there are a lot of modal windows, in order not to make each window, I made one window into which, depending on the call, certain content is substituted.
The problem is this. There is a calculator in modal windows, but after opening the modal window, it doesn't work. As I understand it, it does not work because the window is created on click, and before that it does not exist yet and the calculator does not see it.
Everything works only if the calculator is called together with a modal window.
Question: How can I call the calculator separately from the window, outside the click function.
PS JavaScript began to study recently.
Example: https://codepen.io/OculusDaemon/pen/aqjoxR?editors=1010
Screen calculator
5a8f362499a30813152305.png

Answer the question

In order to leave comments, you need to log in

2 answer(s)
T
twobomb, 2018-02-23
@twobomb

I didn’t understand something, is it just that it should be called immediately without this window like this ?

S
Sergey Sergey, 2018-02-23
@hahenty

All code is impregnated with innerHTML. The problem is really that formInit() is applied to the newly created block via innerHTML. There are a couple of options.
For events to work through a popup, you need to bind handlers to the popup window, for example:

$( '#popup' ).on( 'click', '.plus', function() {
// здесь я не помню, куда будет указывать this
} );

And to bind data from different fields, you need to select them through the context of the popup window.
https://codepen.io/anon/pen/jZpVXB?editors=1010
Here the recalculation of the amount will have to be called when the window is opened, for this you need to redraw the code a little more.
In another way, if, then you need to move the form itself from the hidden block, using the append () function. But then the initialization function for the forms will have to first divide the buttons and input-output fields into groups so that the "plus" button of one form does not increase the value of all amounts in the forms. Here you can apply a cyclic application of a certain single initialization of one form or in event handlers to define the "parent" form of buttons and fields.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question