1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2013
    Rep Power

    How return value from anonymous function called by event?

    Hi at all
    Please take a look at this code

    var return_value="";
    function find(){
    var files = document.getElementById('input').files;
    file = files[0];
    var reader = new FileReader();
    var blob = file.slice(128,132);
    reader.onload = function (event) {
    return_value = event.target.result;

    This script not work because from the anonymous function called by reader.onload I am unable to export return value.
    Therefore my question is:
    How can I do to store the event.target.result value to return_value global variable?

    Thank you very much
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2013
    Rep Power
    Your assumption is wrong, because it's certainly possible to set a global-scope variable's value from within an anonymous function. For example see this jsfiddle.

    Something else is wrong here. Probably reader.onload is never triggered.

IMN logo majestic logo threadwatch logo seochat tools logo