Reputation: 4270
I want to get value of one textbox and put the same in another textbox. my code is :
<input type="text" value="Keyword" id="one" />
<input type="text" value="Search" id="two" />
<a href="#" id="btn">button</a>
jquery:
var input = $("#one");
$('#btn').click(function(){
alert('dgdhjdgj');
var oneValue = $('#one').val();
alert("one value "+ oneValue);
var twoVal = $('#two').val($(input).attr('value'));
alert('two Val' + twoVal);
});
demo is here.
Issue : when I change the value of textbox #one, it does not change the value of #two. thanks in advance.
Upvotes: 0
Views: 3566
Reputation: 455
write textarea and check it. JSFIDDLE
$("#add").click(function(){
var thenVal = $("#textarea_first").val();
$("#textarea_second").val(thenVal);
});
Upvotes: 1
Reputation: 12375
if all that you want to change the text of second textbox, as soon as you change the text of first textbox, just use jQuery's change
event.
just try this then:
$('#one').on("change",function(){
$('#two').val($(this).val());
});
Upvotes: 0
Reputation: 943193
$(input).attr('value')
gets the value of the value attribute, which is the initial value, not the current value.
You had it right two lines earlier. Use val()
.
Upvotes: 2