4

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/

5 Answers 5

10

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>
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks Cybernate.. for reason its not working for me..jsfiddle.net/9tEV2/4
The reason was jQuery was not reference in the jsFiddle post. Updated it. Check: jsfiddle.net/9tEV2/5
5
$('#textbox1').blur(function(e) {

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

});

Comments

4

Non-jQuery solution:

A.onblur = function() { 
    B.value = this.value;
};

Where A and B are references to the text-box elements.

Live demo: http://jsfiddle.net/simevidas/9tEV2/

Comments

3

Hi

try with

$('#Text1').keypress(function () {
    $('#Text2').val($(this).val());
});

I hope it's helpful

Do not consider this post, I didn't read correctly the question

2 Comments

This will change the value on each keypress, even on the non-alphanumeric ones. The author also asked for when the focus is lost. This could be also be expensive, depending on the amount of keystrokes.
@Eli: Sorry! I've not saw "when I leave first text box",I'll edit the post now!
0
<script type="text/javascript">
    $(function () {
        $("#txt1").change(function () {

           $("#text2").val($(this).val());// For Single textBox
            $("#filltext").find("input:text").val($(this).val()) // Fill textbox1 value to multiple textboxes present in a single div(filltext is Division ID)
        });
    })
</script>`

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.