jeudi 26 février 2015

My simple javascript codeeditor have some errors

I have created a simple code editor but i dont know there is something error inside that. The HTML code i have used is



<html>
<head>
<script src="main.js"></script>
<style>
textarea{
width: 33%;
height: 300px;
}
</style>
</head>
<body>
<textarea id="html" width="33%" oninput="validate()"></textarea>
<textarea id="css" width="33%" oninput="validate()"></textarea>
<textarea id="js" width="33%" oninput="validate()"></textarea>
<button onclick="validate()">Compile</button>
<div id="result" ></div>
</body>
</html>


The main.js script is given below:



function validate(){
//get the code values
var html1 = document.getElementById("html").value;
var css1 = document.getElementById("css").value;
var js1 = document.getElementById("js").value;

//Generate the code
var htmltag = "<body>"+ html1 + "</body>";
var csstag = "<style>" + css1 + "</style>";
var jstag = "<script>" + js1 + "</" + "script>";

var totalcode = "<html>" + "<head>"+ csstag + jstag + "</head>" + htmltag + "</html>";

//apply the code
document.getElementById('result').innerHTML = totalcode;

}


no idea but there must be any mistake. and i am new to javascript so i don't have enoufgh knowledge about it :) Thanx for the help in advanced.


Aucun commentaire:

Enregistrer un commentaire