0

I am creating some JSON on the fly, serializing it and saving it to the DB. To run it, i create a script element, and load it that way. Is there a way to load the script source to a textarea?

2
  • To edit the json manually if need be Commented May 27, 2010 at 5:50
  • Fair enough. Just for the record that seems like a bad idea. Commented May 27, 2010 at 5:53

1 Answer 1

1

You don't "run" JSON, JSON is a data notation.

Yes, you can put the text of a script tag into a text area, something along these lines:

var script, tb, node;
script = document.getElementById('theScriptID');
tb = document.getElementById('theTextBoxID');
tb.innerHTML = script.innerHTML;

Example:

<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-type" content="text/html;charset=UTF-8">
<title>Test Page</title>
<style type='text/css'>
body {
    font-family: sans-serif;
}
</style>
<script id='theScriptID' type='text/javascript'>

    function go() {
        var script, tb;
        script = document.getElementById('theScriptID');
        tb = document.getElementById('theTextBoxID');
        tb.innerHTML = script.innerHTML;
    }

</script>
</head>
<body>
<textarea id='theTextBoxID' rows='20' cols='70'></textarea>
<input type='button' id='btnGo' value='Go' onclick="return go();">
</body>
</html>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.