How to get a input value from the string using javascript.
Use "eval" function to get input value from the string.
Example:
<form>
<input type="text" name="test" id="test" value="1" />
<input type="button" name="te" onclick="testing()" />
</form>
<script>
function testing() {
var st = "document.getElementById('test').value";
<input type="text" name="test" id="test" value="1" />
<input type="button" name="te" onclick="testing()" />
</form>
<script>
function testing() {
var st = "document.getElementById('test').value";
alert(st);
//output: document.getElementById('test').value
//output : 1
//output : 1
alert(eval(st));
//output : 1}
</script>
No comments:
Post a Comment