Wednesday, June 23, 2010

Convert String Into object using javascript

Convert String Into object using javascript:

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";
   alert(st);
//output:  document.getElementById('test').value
  //output : 1
   alert(eval(st));
  //output : 1
  }
</script>

No comments:

Post a Comment

 

Followers