T
T
Timofey Mikhailov2018-01-18 10:24:44
Windows
Timofey Mikhailov, 2018-01-18 10:24:44

Process code written in textarea?

The idea is this. The form has a <textarea id="code"></textarea>, in which I write the code.
Let's say:
===========================
var t=5, z=6, m;
m=t+z;
=============================
Next, we have the following component: <div id="result"></div>, where I would like to output the result ... But how to do it I don't really know... Any advice?
============================
Here's what else is important, I would like to solve the problem using only the possibilities of JavaScript, without PHP or any Frameworks ....
============================
Thank you!

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alex McArrow, 2018-01-18
@JimmiJanger

eval eval('code here') is a help to you - it will be executed as
code . read text from textarea into variable, into eval and result into div

J
JackShcherbakov, 2018-01-18
@JackShcherbakov

Try adding a script element to the page and write the entire text content of the text area to the innerHTML of that element.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question