0

Here I am trying to achieve callback function by passing function to another.In below example onclick button calling invoke_reporting first parameter textdata is having some data in text format. Also passing callback but not getting called.

function invoke_reporting(textdata,callback) {
 window.open("http://192.168.17.109/TestCopy_Report1/templates/ct-scan-head");
 if (callback && typeof(callback) === "function") {
 callback(textdata);
 }
}
function callback(finaldata){
 alertify("callback function");
 document.getElementById("post-data").innerHTML = finaldata;
 window.opener.document.getElementById('post-data').value = finaldata;
}

And in the newly opened window I want to assign textdata value into this new opened window textarea.

Here is my HTML Code:

<form id="report">
 <div class="form-group">
 <label for="post-data">Report Data(Text Format):</label>&nbsp;&nbsp;
 <textarea class="form-control" rows="20" id="post-data" name="post-data"></textarea>
 </div>
 <div class="form-group">
 <div class="col-sm-6"><button type="submit" class="btn btn-primary btn-block" name="launch" id="launch" onclick="invoke_reporting(document.getElementById('post-data').value)">Launch</button>
 </div>
 </div>
</form>

Any help would be appreciated.

asked Oct 16, 2018 at 5:03
3
  • 2
    What are you invoking the functions with? I don't see any invocations in your current code Commented Oct 16, 2018 at 5:04
  • Getting text area data onclick invoking_report. This data I want to show in the newly opened window using callback functions. Commented Oct 16, 2018 at 5:05
  • 2
    Please post the actual code so we can look at it. Commented Oct 16, 2018 at 5:06

1 Answer 1

2

It seems you are not passing the callback function to the invoke_reporting function

change this

<div class="col-sm-6"><button type="submit" class="btn btn-primary btn-block" name="launch" id="launch" onclick="invoke_reporting(document.getElementById('post-data').value)">Launch</button>

to

<div class="col-sm-6"><button type="submit" class="btn btn-primary btn-block" name="launch" id="launch" onclick="invoke_reporting(document.getElementById('post-data').value,callback)">Launch</button>

DEMO HERE

hope this helps.

EDIT

To set value in the textarea of newly opened window try the following code.

function invoke_reporting(textdata,callback) {
 var newwindow = window.open("http://192.168.17.109/TestCopy_Report1/templates/ct-scan-head");
 if (callback && typeof(callback) === "function") {
 callback(textdata,newwindow);
 }
}
function callback(finaldata,newwindow){
 alertify("callback function");
 newwindow.onload = function(){
 newwindow.document.getElementById('post-data').value = finaldata;
 };
}

i got answer from this SO post

answered Oct 16, 2018 at 5:15
Sign up to request clarification or add additional context in comments.

1 Comment

Callback works fine thank you. How can I assign that data into newly opened windw textarea.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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