1

In html.erb, I have 2 functions which establish a session and disconnection session:

<script>
    var session = initialize_session()
    disconnect_session(session)

    function initialize_session() {
        session = session_init();
        return session;
    }

    function disconnect_session(session) {
        session_end(session);
    }

</script>

But the above code errors out. How to get the value from one JavaScript function and pass it to another in JavaScript? Thank you.

3
  • Do you want some value to used in another page or pass some value from one fucntion to another function Commented Dec 28, 2018 at 5:59
  • Pass the session object from initialize_session() to disconnect_session(), so answer to your question from one function to another Commented Dec 28, 2018 at 6:03
  • Please check my solution Commented Dec 28, 2018 at 6:11

1 Answer 1

2

var session = initialize_session()
function initialize_session(){  
   var data = {id:"123456789"};
   return data; 
}
disconnect_session(session)
function disconnect_session(seesion){
  alert('Disconnect the session'+session.id)
}

The above is the working example

Sign up to request clarification or add additional context in comments.

2 Comments

You can also pass the object
Welcome @UmaSenthil

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.