Reputation: 885
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.
Upvotes: 0
Views: 4091
Reputation: 11
Give onchange event for first field and assign value for second field,as below
onchange="secondfieldname.value=firstfieldnamefieldname.value"
Upvotes: 0
Reputation: 70139
The change
event only fires when 2 conditions are met:
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());
});
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());
});
Upvotes: 1
Reputation: 146191
$(function(){
$('#txt1').on('change', function(e){
$('#txt2').val($(this).val());
});
});
Upvotes: 1
Reputation: 94319
$("#field1").change(function(){
$("#field2").val(this.value);
});
Demo: http://jsfiddle.net/DerekL/CcDv4/
Upvotes: 3