0

I am attempting to bind to the file attachment OK button which has an id of c100_PlaceHolderMain_btnOK.

I've tried

$('#ct100_PlaceHolderMain_btnOK').click(function() {

});

and

$(document).on('click', '#ct100_PlaceHolderMain_btnOK', function(e) {

});

but neither works, the functions never get called when the button gets clicked. Specifically I want to trigger the SPshowWaitWithNoClose to show when the user hits OK and then close once the result returns in the callback.

How can I get this working and why isn't jQuery able to bind to the button?

3
  • Do you declare this button in your server code (page, web part, user control)? Try to set onclick attribute. Are there some errors in console log? Commented Nov 10, 2017 at 6:35
  • No this is the button from the SP File Attachment modal which is gotten by calling SP.UI.ModalDialog.showModalDialog(options) and in the options object, the url is _spPageContextInfo.webAbsoluteUrl + "/_layouts/Attachfile.aspx?ListId=" + engListGUID + "&ItemId=" + row.ID; So its the "OK" Button in the modal that pops up from that url Commented Nov 10, 2017 at 6:38
  • Just noticed the dialog is nested inside an iFrame so I assume this makes it trickier since its technically a webpage basically opened as a modal Commented Nov 10, 2017 at 6:44

1 Answer 1

0

Your JS code applies for your main page, but not for new modal dialog. If you want to continiue use modal dialog, try to get DOM of this page. Something like this:

//wait for modal loaded
setTimeout(myFunction, 400);
function myFunction(){
  dialog = SP.UI.ModalDialog.get_childDialog();
  $(dialog.$e_0).find("#buttonId").on("click", fucntion(){alert()})
}
3
  • error: object does not support method get_childDialog(); Commented Nov 10, 2017 at 7:02
  • Assign method call to variable: var dialog = SP.UI.ModalDialog.showModalDialog(options); then work with this variable as shown above. Also, take a point that setTimeout is not good idea too, because modal dialog can open in 200 ms or 2 seconds, when timout is 400ms. And your function can call when modal page DOM is not ready. Commented Nov 10, 2017 at 7:18
  • I'm exploring an option to use the IFrame.contents which should then give me access to its DOM...I should be able to us the .on('load') event to wait for it to load and then find the element I need...I will test this out and see what happens... Commented Nov 10, 2017 at 7:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.