Before you name it as a duplicate, I already looked here , here , but I can not find a working solution. I understand that I cannot pass the script to innerHTML due to the script tag. But is it possible to promote this particular API in a div without putting it on an HTML page. I have a button that accepts the input and runs the $ .get pair to get stock information, so I want to include this as part of the result, however innerHTML is not allowed, and I tried to execute many of these solutions in the links above, to no avail.
I can place the script below in the div on the HTML page, but I do not want to do this, plus I need to get the user input, so placing it inside my .js will be much easier to perform all functions together, I turned on the js widget.
<script type="text/javascript"> new TradingView.widget({ "width": 480, "height": 400, "symbol": "NASDAQ:AAPL", "interval": "D", "timezone": "Etc/UTC", "theme": "White", "style": "1", "locale": "en", "toolbar_bg": "#f1f3f6", "enable_publishing": false, "hide_top_toolbar": true, "save_image": false, "hideideas": true }); </script>
I still have
var script = document.createElement('script'); script[(script.innerText===undefined?"textContent":"innerText")] = "new TradingView.widget({ 'width': 580, 'height': 400, 'symbol': 'NASDAQ:"+ticker+ "','interval': 'D','timezone': 'Etc/UTC','theme': 'White','style': '1','locale': 'en','toolbar_bg': '#f1f3f6','enable_publishing': false,'hide_top_toolbar': true,'save_image': false,'hideideas': true});"; document.getElementById("stockChart").appendChild(script);
And this work, but not the way I want, however, it is simple to execute that script, and this diagram is the only thing that appears on the page, is there a way I can make it be in a <div> ? With the above solution, the script is executed, but not placing the widget inside the div (it seems I could be wrong. I do not own this).
In this image, when I run a script with a JS file with other operations, it just displays the graph on its own on the page.
This is when the code is inside the div and before running any JS functions, I think it is in the div, however I need to put the text entered above in the field so that all the information is displayed on one page, as shown below
I want the graph to be at the red dot, where <div> is
HTML
<div id="content"> <img src="icon/logo.png"> <h1>Search Shares</h1> <div id="stockTickGet"> Ticker: <input type="text" id="tickBox" list="options"/> <button onclick="Ticker()" id="tickerSubmit" class="btn btn-primary">Submit</button> <datalist id="options"></datalist> </div> <div id='showStockTick' class='stockTicker'></div> <div id='stockChart'> </div> <div id='showStockSearch' class='stockTicker'></div> <div id='newsresult' class='stockTicker'></div> <button class="btn btn-primary" data-toggle="modal" data-target="#modal1">Buy Stocks</button> </div>
In a way, this is what I want to do, but not allowed / works
document.getElementById("stockChart").innerHTML = "<script> new TradingView.widget({ 'width': 580, 'height': 400, 'symbol': 'NASDAQ:GOOG','interval': 'D','timezone': 'Etc/UTC','theme': 'White','style': '1','locale': 'en','toolbar_bg': '#f1f3f6','enable_publishing': false,'hide_top_toolbar': true,'save_image': false,'hideideas': true});<"+"/script>";