Ravi
Ravi

Reputation: 31397

onchange text of textbox display on another textbox

I want to display changing text into another text box

I tried here for evey possible combination. But didn't work.

/*$('input#list_val').keyup(function() {
   //perform ajax call...
  // alert("Hello");
   $('#list_v').text($(this).val());
});*/
$('input#list_val').keydown(function() {
   //perform ajax call...
   //alert("Hello");
   $('#list_v').text($(this).val());
});


<input type='text' id="list_val" />
<input type='text' id="list_v" />

Upvotes: 1

Views: 2955

Answers (7)

Anup
Anup

Reputation: 3353

Your code is perfect, Just need to change small things in your code :

$('#list_val').keydown(function() {  
   $('#list_v').val($(this).val());
});

Upvotes: 0

Deepak Rajpal
Deepak Rajpal

Reputation: 1011

Try this:

$('input#list_val').keydown(function() {
    var text = $("input#list_val").val();
    $('#list_v').html(text);
});

Upvotes: 0

Sandip
Sandip

Reputation: 374

Try This

js

$('#list_val').keyup(function() {
   $('#list_v').val($('#list_val').val());
});

Demo

Upvotes: 0

Arun P Johny
Arun P Johny

Reputation: 388316

var $list_v = $('#list_v');
$('input#list_val').keyup(function() {
   $list_v.val($(this).val());
});

Demo: Fiddle

Upvotes: 0

Ganesh Pandhere
Ganesh Pandhere

Reputation: 1652

change from :

$('#list_v').text($(this).val());

to:

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

Upvotes: 0

Greenhorn
Greenhorn

Reputation: 1700

It should be val() for adding value to input and use keyup rather than keydown to show value in other input immediately

$('input#list_val').keyup(function() {
   $('#list_v').val($(this).val());
});

Demo Fiddle

Upvotes: 4

Anton
Anton

Reputation: 32581

use .val() and .keyup (using keydown doesn't register the newest value, it registers the value before so keyup is better to use for this)

$('#list_val').keyup(function() {
   $('#list_v').val(this.value);
});

DEMO

Upvotes: 1

Related Questions