title: jquery val() method error, unable to set value instead getting value Undefined even it shows value in console.log()
body: <p>I wanted to make an input value same to above input val using jquery.The above input type val is coming from a function. But don't know why the second input value is being set to undeefined and console gives no error.</p>
  
  <p>HTML :</p>
  
  <pre><code>&lt;input type="hidden" name="date" id="transactiona_date"&gt;
  </code></pre>
  
  <p>I Tried jquery 1.</p>
  
  <pre><code>console.log($("#myDate").val());
  $("#transactiona_date").val($("#myDate").val());
  console.log($("#transactiona_date").val());
  </code></pre>
  
  <p>2.</p>
  
  <pre><code>console.log($("#myDate").val());
  $('#transactiona_date').val($("#myDate").val());
  console.log($("#transactiona_date").val());
  </code></pre>
  
  <p>I even tried changing id to class in jquery as well as in html</p>
  
  <p></p>
  
  <pre><code>console.log($("#myDate").val());
  $(".transactiona_date").val($("#myDate").val());
  console.log($(".transactiona_date").val());
  </code></pre>
  
  <p>No matter what i do i always get this in console.</p>
  
  <pre><code>06-02-2018
  undefined
  </code></pre>
  
  <p>Any help why it is behaving like this ?</p>
  
  <p>Also the myDate is getting value from</p>
  
  <pre><code>&lt;input style="width:98%;margin-left:1%;margin:right:1%" type="text" name="invoice_date" id="myDate" value="&lt;?php echo date('d-m-Y'); ?&gt;"&gt;
  </code></pre>
  
  <p>Also i have no other error showing in console.And i want to share that the following id's or there is no other thing or code containing a relation to this code in same page , still lets consider a possibility of something interfering with the code, can you suggest a suitable way to diagnose my problem or how can i check what's been wrong in my code.</p>