title: codeigniter trying to access session data from view using javascript
body: <p>Framework: CodeIgniter 2.0</p>
  
  <p>I am trying access session data setup in model from view.</p>
  
  <p>This is the code I am testing in view:</p>
  
  <pre><code>&lt;script type='text/javascript'&gt;
    function notEmpty(elem, helperMsg){
      var num_records = '$this-&gt;session-&gt;userdata("number_Of_Records_session")';
      alert(num_records);
      if(elem.value.length &gt; 0){
        alert(helperMsg);
        elem.focus();
        return false;
      }else{
        window.location="/path/";
      }
      return true;
    }
  &lt;/script&gt;
  </code></pre>
  
  <p>When I use PHP code I could retrieve the value from session and display it.</p>
  
  <pre><code>&lt;?php 
      $numberOfRecords_session = 
      $this-&gt;session-&gt;userdata('number_Of_Records_session');
      echo "Num records:".$numberOfRecords_session;
  ?&gt;
  </code></pre>
  
  <p>But in javascript this line</p>
  
  <pre><code>var num_records = '$this-&gt;session-&gt;userdata("number_Of_Records_session")';
  </code></pre>
  
  <p>print this message in alert box:</p>
  
  <pre><code>$this-&gt;session-&gt;userdata("number_Of_Records_session")
  </code></pre>
  
  <p>Any advice to retrieve value in javascript and show it alert box is appreciate.</p>