I'm trying to create a html/css/javascript online editor for people to try small code and stuff like that.
it was actually pretty simple.. you create 2 div
's one is a textarea
id="input"
and the other is a div
id="output"
and you create a js function to push the content of the input into the output either by pressing a button or make it live by running the function every 2 seconds or something
I ran the code and it worked fine for html and css but once i tried to create a function inside <script>
tags inside that textarea
it didn't actually run.. like it doesn't exist..
I can run small functions using a button if i wrote the actions inside the onclick
but to define a function and then run it by that button is not working
window.setInterval(function(){
var y = document.getElementById("automatic").checked
if (y==1){
editorFunction()
}
}, 1000);
function editorFunction(){
var x = document.getElementById("input").value;
document.getElementById("output").innerHTML = x;
}
My question is.. is there a way around this ? i really want the page to stay static.. i don't want to have to send the content to a database and make a new form and render it on the page.. i wanna keep it as simple as possible Someone asked for the html.. I don't think it's important but here it is:
<body id="body">
<section class="container">
<div class="row">
<div class="col-sm-6">
<textarea class="col-sm-12" id="input"></textarea>
</div>
<div class="col-sm-6">
<div class="col-sm-12" id="output"></div>
</div>
</div>
</section>
<section>
<div class="row">
<div class="col-sm-3"></div>
<div class="col-sm-6">
<button onclick="editorFunction()">RUN</button>
<input type="checkbox" id="automatic" checked>Submit the changes LIVE</input>
</div>
</div>
</section>
</body>
eval() will only work when i want to execute an action.. i can't really define a function that will stay for later use