title: pass variable value in hidden text field in jquery
body: <p>Hey guys I want to pass variable pid value to hidden text field pid but unable to do so.</p>
  
  <p>HTML code:</p>
  
  <pre><code>&lt;div id="overlay_forma"&gt;
  &lt;h4&gt;Another popup&lt;/h4&gt;
  
  &lt;input id="addElement" type="button" value="Add to Form" /&gt;
  &lt;input id="removeElement" type="button" value="Remove" /&gt;
  &lt;form id="samplecode" name="samplecode" method="POST" action="&lt;%= request.getContextPath() %&gt;/AddProjectTaskDAO"&gt;
   &lt;fieldset&gt;
    &lt;legend&gt;&lt;b&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;Dynamically added form elements&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/b&gt;&lt;/legend&gt;
    &lt;div id="generatedForm"&gt;
     &lt;div&gt;
      &lt;input id="processForm" type="submit" value="Submit to Process" /&gt;
     &lt;/div&gt;  
    &lt;/div&gt;
   &lt;/fieldset&gt;
   &lt;/form&gt;
   &lt;center&gt;&lt;a href="#" id="closea" &gt;Close&lt;/a&gt;&lt;/center&gt;
   &lt;/div&gt;
  </code></pre>
  
  <p>jQuery code:</p>
  
  <pre><code>var counter = 1;
  
  $("#addElement").click(function(event){
  
   var pid=$('#addElement').data('pid');
   var pname=$('#addElement').data('pname');
  
   if(counter&gt;10){
       alert("Only 10 textboxes allow");
       return false;
  }   
  
   var $newDiv = $(document.createElement('div'))
  
    .attr("id", 'TextBoxDiv' + counter);
  
   var $newInput = $("&lt;label&gt;Input Box: &lt;/label&gt;" + "&lt;input type='hidden' id='pid' name='pid' value='pid'&gt;" + "&lt;select name='uname'&gt;&lt;c:forEach items='${ual}' var='u'&gt;&lt;option value='&lt;c:out value='${u.uname}'&gt;&lt;/c:out&gt;'&gt;&lt;c:out value='${u.uname}'&gt;&lt;/c:out&gt;&lt;/option&gt;&lt;/c:forEach&gt;&lt;/select&gt;" + "&lt;textarea rows='5' cols='15'&gt;&lt;/textarea&gt;" + "&lt;input type='text'&gt;");
   $newInput
     .attr("name", "$('#addElement').data('pid')" + counter)
     .addClass("text")
     .attr("name", "uname" + counter)
     .addClass("text")
     .attr("name", "ptdesc_emp" + counter)
     .addClass("text")
     .attr("name", "ptestd_time_alloc" + counter)
     .addClass("text");
   $newInput.appendTo($newDiv);
   $newDiv.appendTo($("#generatedForm"));
  
   counter++;
  
   });
  </code></pre>
  
  <p>I have also tried adding $('#addElement').data('pid') instead of pid in val of hidden text field but still unable to show the output of pid.</p>
  
  <p>Any help is appreciated.</p>