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.
$(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()
.
Try this
HTML
<input type="text" placeholder="Keyword" id="one" />
<input type="text" placeholder="Search" id="two" />
<a href="#" id="btn">button</a>
Script
$('#btn').click(function() {
var oneValue = $('#one').val();
$('#two').val(oneValue)
})
write textarea and check it. JSFIDDLE
$("#add").click(function(){
var thenVal = $("#textarea_first").val();
$("#textarea_second").val(thenVal);
});
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());
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.