execute a script by pressing a date attribute button

Asked

Viewed 230 times

0

I made an html form, put it on a platform that loads this form. However, there are platform buttons that perform functions in the form (such as sending the form, saving and so on). Then I discovered that I can manipulate these platform buttons with code inside the form using this:

window.parent

for example, I can drop an Alert when a certain platform button is pressed with that code:

window.parent.$(".fixedTopBar").find("button").on("click", function(ev) { alert("OK"); });

Ai, I have this button (which logically I can not change it, because it is the platform):

<button type="button" class="btn btn-primary" data-send="">Enviar</button>

And I want to run a script when it’s pressed... As I have other buttons on the page, I decided to capture the "on(click)" button with the data-send (since it is unique in this).

I tried codes like:

window.parent.$('[data-send]').on("click", function(ev) { alert("OK"); ); 

window.parent.$('button[data-send]').on("click", function(ev) { alert("OK"); );    

window.parent.$('button').data("send").on("click", function(ev) { alert("OK"); }); 

But it didn’t work. I don’t understand much about the date attribute... It must be from the difficulty of understanding how to use it.

If it’s better, I drew it like this: [Red] Environment [Blue] form [Green Arrow] Button I want to capture the click

Exemplo

  • 1

    Is that button present when the page loads? Test $(document).on("click", '[data-send]', function(ev) { alert("OK"); );

  • Actually, I didn’t post the whole code... It’s a window that gets outside the document... I use a: window.parent. before.

  • As if the widget is outside the document?

  • This is inside a platform that a window loads an external document so that button I want to capture is in the window, not in the document... I’ve done tests like: window.parent. $("#workflowActions"). on("click", Function(Ev) { va(Ev); }); and it works...

  • Solved! Added in question and here: window.parent.$("[data-send='']").on("click", function(ev) { validateForms(ev); });

  • 1

    Do not post your solution by editing the question; for this there is the answer area. There are no problems in answering the question itself; in fact, this is quite common here, but try to structure it well, not just with a line of code, but with an explanation of why it didn’t work the way it was and why its code solved the problem. If you do not fully understand why the solution works and the others presented in the question does not, your problem has not yet been solved.

  • Especially because his example of $('button[data-send]') should work. See here.

Show 2 more comments

1 answer

0


Problem solved. First I had to make a change: instead of using the select button, I used the data-send attribute, because there is another element in the sending environment (and it also has the same data-send attribute) but it is not a button. That is, of that code:

$('button[data-send]')

I went to this code:

$("[data-send]")

Thus, the script encompasses the two cases.

About this question code not working:

window.parent.$('[data-send]').on("click", function(ev) { alert("OK"); );

It works normally, must have happened some problem (or the platform, or cache or even some quotes or missing point) and when I ran I thought it did not work.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.