javascript - Accessing a variable obtained by user from separate file in JS -


a beginner question:

i'd create app obtain imaginary number user , plot complex plane. since i'm hoping add other things later, keep code in separate files, connected in html file.

in first file, real , complex part user:

$(document).ready(function() { $("#button-number").click(function() {     var realpart = prompt("please, enter real part of number:")     var imagpart = prompt("please, enter imaginary part of number:") });}) 

which use in second file:

$(document).ready(function() { var c = document.getelementbyid("complexplane"); var number = c.getcontext("2d"); number.beginpath(); number.arc(500+50*realpart,300-50*imagpart,10,0,2*math.pi); number.stroke(); number.fill();}) 

however, doesn't work. works if define variables manually outside function. i'm not entirely sure how operations timed, since variables aren't defined when document loads. i'd love know how solve issue.

this works expected.

instead using global variable scope use localstorage

http://www.w3schools.com/html/html5_webstorage.asp

you can store real imaginary part numbers in localstorage in first file. , can access them in second file.


Comments

Popular posts from this blog

sequelize.js - Sequelize group by with association includes id -

android - Robolectric "INTERNET permission is required" -

java - Android raising EPERM (Operation not permitted) when attempting to send UDP packet after network connection -