how to auto populate text fields with text automatically

I have a simple Registration form and I want to make an option like there are two different fields, and what i want is simple, just when I add text to the first field it should automatically be added the same content to the next field.

Answers


$("#field1").change(function(){
    $("#field2").val(this.value);
});

Demo: http://jsfiddle.net/DerekL/CcDv4/


$(function(){
    $('#txt1').on('change', function(e){
        $('#txt2').val($(this).val());
    });
});​

DEMO.


The change event only fires when 2 conditions are met:

  • The element loses focus;
  • The element has a different value property than when it got focus.

If you want the text to change as you type it, you can use jQuery together with the HTML5 input event:

//assuming `a` and `b` as text field IDs
$('#a').on('input', function() {
   $('#b').val($(this).val());
});​

JSFiddle

For non-HTML5 browsers, you can just extend the events map to simulate the input event:

$('#a').on('input keydown keypress keyup change blur', function() {
    $('#b').val($(this).val());
 });​

JSFiddle


Give onchange event for first field and assign value for second field,as below

onchange="secondfieldname.value=firstfieldnamefieldname.value"

Need Your Help

How to correct character encoding in IE8 native json?

javascript json internet-explorer unicode encoding

I am using json with unicode text, and am having a problem with the IE8 native json implementation.

Why does newList = list.remove(x) return None?

python syntax

I have a list below and I want to remove a value and set it to a new variable. Why does it return None?