-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
32 lines (31 loc) · 1.62 KB
/
script.js
File metadata and controls
32 lines (31 loc) · 1.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
// fn for changing textbox according to button selected by the user
function codeboxhandler(buttontype) {
// firstly we hide all the textbox
document.getElementById("htmlbox").style.display="none";
document.getElementById("cssbox").style.display="none";
document.getElementById("jsbox").style.display="none";
document.getElementById("htmlbutton").style.backgroundColor="white";
document.getElementById("cssbutton").style.backgroundColor="white";
document.getElementById("jsbutton").style.backgroundColor="white";
// now changing the textbox based on condition as selected by the user
if (buttontype=="htmlbutton") {
document.getElementById("htmlbox").style.display="block";
document.getElementById("htmlbutton").style.backgroundColor="yellow";
}
else if (buttontype=="cssbutton") {
document.getElementById("cssbox").style.display="block";
document.getElementById("cssbutton").style.backgroundColor="blue";
}
else {
document.getElementById("jsbox").style.display="block";
document.getElementById("jsbutton").style.backgroundColor="red";
}
}
// fn that executes the code every time user input in textbox
function runcode() {
const htmlcode=document.getElementById('htmlcode').value;
const csscode=document.getElementById('csscode').value;
const jscode=document.getElementById('jscode').value;
const fullcode=htmlcode+"<style>"+csscode+"</style>"+"<script>"+jscode+"</script>"; // putting all html css js reference in a variable
document.getElementById('outputbox').srcdoc=fullcode; // now giving the fullcode in refernce of iframe for output
}