If you can put some part of the dialog (even just a placeholder div
where you will insert the dialog's HTML) in the HTML that loads at page load, you can use delegated events in jQuery to attach event handlers to descendant elements that don't exist in the DOM at page load (like your dialog's elements).
See jQuery documentation for on()
.
This will bind an event handler to the click
event for a button with ID myButtonId
added to the DOM at any point in the future as long as it is inside the placeholder div
:
<div id="divPlaceholder"><!-- dialog will be inserted into DOM here --></div>
<script type="text/javascript">
$($("#divPlaceholder").on("click", "#myButtonId", function() {
window.open(...);
}));
</script>
Alternatively, whatever script you have running when the user clicks "add records" in order to display the jqGrid dialog could display the dialog, then add the event handler directly to the button.