Theo E
Theo E

Reputation: 77

How do I get the data stored in value in JQuery?

I have the following input box, and I want to get its value.

 <input id="dontuse" name="post_tag" 
 value="sdafdsfds,adsfdsfdsfdsaf,sadfdsfdsfasd,asdfdsfsd,czxczXCzzx" 
 data-output="bootstrap" class="wpt-form-hidden form-hidden" data-wpt- 
id="dontuse" data-wpt-name="post_tag" type="hidden">

The following returns the data in the textbox (by another element tmp_post_tag.

 $(document).ready(function(){
 $('input[name="tmp_post_tag"]').keyup(function(e){
   var val = $(this).val();
   $("#fieldID3").val(val);
 });
 });

but it only returns whats in the textbox (if user presses enter the data gets stored in "value" on post_tag and disappears from text box.

How do I get the data stored in "value" to input here:

 <input type="text" id="fieldID3" name="test" value="n/a">

this is what i've tried, and haven't gotten it to give me the data.

 $(document).ready(function(){
 $('input[name="post_tag"]')
   var val = $(this).val();
   $("#fieldID3").val(val);
 });

Upvotes: 0

Views: 48

Answers (2)

Mamun
Mamun

Reputation: 68933

The attribute value used for name in the code dose not match with the one in the element. It should be post_tag not tmp_post_tag. Also how do you keyup on a element which is not visible? Though you can trigger the event in the code.

$(document).ready(function(){
  $('input[name="post_tag"]').keyup(function(e){
    var val = $('input[name="post_tag"]').val();
    $("#fieldID3").val(val);
  });
  $('input[name="post_tag"]').trigger('keyup');
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input id="dontuse" name="post_tag" 
 value="sdafdsfds,adsfdsfdsfdsaf,sadfdsfdsfasd,asdfdsfsd,czxczXCzzx" 
 data-output="bootstrap" class="wpt-form-hidden form-hidden" data-wpt- 
id="dontuse" data-wpt-name="post_tag" type="hidden">


<input type="text" id="fieldID3" name="test" value="n/a">

Upvotes: 1

Talg123
Talg123

Reputation: 1506

if I managed to understand your currectly.

 $(document).ready(function(){
 $('input[name="tmp_post_tag"]').keyup(function(e){
   var val = $(this).val();
   $("#fieldID3").val()+val;
 });
 });

Upvotes: 1

Related Questions