samuvk Posted September 25, 2015 Share Posted September 25, 2015 I have values stored in a variable in Javascript in this way: var VariableCity = "Birmingham" var VariableCapital = "Montgomery" Now I would like to write the value stored in the variable in a determinated place in the HTML document as below. How can I accomplish that? I tried: document.write(VariableCity) but: 1. I got this error: "Failed to execute 'write' on 'Document': It isn't possible to write into a document from an asynchronously-loaded external script unless it is explicitly opened." 2. That way I'm not indicating where to write it THANK YOU SO MUCH!!!!! <body> <div style="width:100%;border:0px solid #ededed;"> <div style="float:left;width:5%;"> <select id="SystemSelector" onChange="sendAndDraw(this.value)"> <option value="Al">Alabama</option> <option value="Tx">Texas</option> </select> </div> <div style="float:left;width:95%;"> <button onclick="loadEditor(SystemSelector.value)">Change type of Graph</button> City: VariableCity <div id="Piechart_div" style="width: 100%;"></div> </div> </div> <div style="width:100%;border:0px solid #ededed;"> <div id="chartGauge_div" align='center' style="width:100%"></div> Capital: VariableCapital </div> </body> Link to comment Share on other sites More sharing options...
justsomeguy Posted September 25, 2015 Share Posted September 25, 2015 Put an element on the page with a certain ID, and in Javascript use document.getElementById to get that element and then you can use the innerHTML property to set the contents of it to your variable. Link to comment Share on other sites More sharing options...
solutionstack Posted September 27, 2015 Share Posted September 27, 2015 Yeah just call the innerHTML or textContent property of an element you wish to insert into Link to comment Share on other sites More sharing options...
samuvk Posted September 28, 2015 Author Share Posted September 28, 2015 And how do I do that? Never done it before and have not clue how to proceed Thanks!!!!!!!!! Link to comment Share on other sites More sharing options...
dsonesuk Posted September 28, 2015 Share Posted September 28, 2015 http://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_document_getelementbyid Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now