Reading json from hidden input value with JSON.parse() - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Form Event

Description

Reading json from hidden input value with JSON.parse()

Demo Code

ResultView the demo in separate window

<html>
   <head></head>
   <body> 
      <input id="hdn" type="hidden" value="{&quot;products&quot;:{&quot;id&quot;:100001,&quot;name&quot;:&quot;TESTTTT&quot;}}"> 
      <script type="text/javascript">
            var jsonObj = JSON.parse(document.getElementById('hdn').value);
            console.log(jsonObj);
            console.log(jsonObj.products.name);
            console.log(jsonObj);
            console.log(jsonObj.products.name);
        //from   w  ww . j  a  va2 s  .c  o  m
      </script>  
   </body>
</html>

Related Tutorials