Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to assign Textbox value to the other textbox using jquery

I have two textboxes in my view,

My requirement is when I enter some text in the first textbox automatically that value should be assigned to second text box when I leave first textbox. using jquery or javascript.

thanks for your help

EDIT:

For Some reason this code is not inserting the value into seconed textbox.

http://jsfiddle.net/9tEV2/4/
like image 241
kumar Avatar asked Nov 29 '22 17:11

kumar


2 Answers

Capture the onchange event of the first textbox and in the event handler assign the first textbox value to second one.

Something like:

<input type="text" id="name"/>
<input type="text" id="anotherName"/>

<script type="text/javascript">
$(function(){
  $("#name").change(function(){
   $("#anotherName").val($(this).val());
  });
})
</script>
like image 150
Chandu Avatar answered Dec 05 '22 06:12

Chandu


$('#textbox1').blur(function(e) {

    $('#textbox2').val($(this).val());

});
like image 32
Eli Avatar answered Dec 05 '22 06:12

Eli