title: Not able to access the value of hidden field in Jquery
body: <p>I am trying to set the value of hidden field on the click of list item. However the value is not getting set</p>
  
  <p>Here is my PHP/HTML code:</p>
  
  <pre class="lang-html prettyprint-override"><code>&lt;div class = "input-group-btn"&gt;
      &lt;input type=""hidden name="cpnoselected" value="asd"&gt;
      &lt;button type = "button" class = " form-control btn btn-primary dropdown-toggle dropdown-toggle" data-toggle = "dropdown"&gt; CP No. &lt;span class = "caret"&gt;&lt;/span&gt; &lt;/button&gt;
          &lt;ul class = "dropdown-menu selectcpno" name="selectcpno"&gt;
              &lt;?php
                      $link_address="#";
                      $class_active="active";
                      while($row=  mysqli_fetch_assoc($result_rows_cpdetailsfordd))
                      {   
                          if($result_rows_cpdetails[0]==$row['cp_no']){
                              echo "&lt;li value='".$row['cp_no']. "'class='".$class_active."'&gt;&lt;a href='".$link_address."'&gt;" . $row['cp_no'] ."&lt;/a&gt;&lt;/li&gt;";
                          }
                          else{
                              echo "&lt;li value='".$row['cp_no']."'&gt;&lt;a href='".$link_address."'&gt;" . $row['cp_no'] ."&lt;/a&gt;&lt;/li&gt;";
                          }
                      }
              ?&gt; 
              &lt;li class = "divider"&gt;&lt;/li&gt;
  
              &lt;?php
                  $class_active="active";
                  $link_address="#";
                  if($result_rows_cpdetails[0]==""){
                      echo "&lt;li value='".$row['cp_no']. "'class='".$class_active."'&gt;&lt;a href = '".$link_address."'&gt;Package Level&lt;/a&gt;&lt;/li&gt;";
                  }
                  else{
                      echo "&lt;li value='".$row['cp_no']."' &gt;&lt;a href = '".$link_address."'&gt;Package Level&lt;/a&gt;&lt;/li&gt;";
                  }
              ?&gt;
          &lt;/ul&gt;
     &lt;/div&gt;&lt;!-- /btn-group --&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>Here is the Javascript functionL</p>
  
  <pre><code>$('.selectcpno li').click(function(){
      //Get the value
      var value = $(this).attr("value");
      //Put the retrieved value into the hidden input
      $('input[name=cpnoselected]').val(value);
  }); 
  </code></pre>
  
  <p>i am getting undefined index error on accessing the value through $_POST variable</p>