最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Two textbox change at same time [JQuery] - Stack Overflow

programmeradmin4浏览0评论

I have two textboxes one is type='text' and second is type='hidden'.I want to when something is typed in first textbox to set same value in the second automatically.

I tried something with .change(), but it was not good.

In short: I want same value on both textboxes at sometime [real time]

Do you have some idea how to do it?

I have two textboxes one is type='text' and second is type='hidden'.I want to when something is typed in first textbox to set same value in the second automatically.

I tried something with .change(), but it was not good.

In short: I want same value on both textboxes at sometime [real time]

Do you have some idea how to do it?

Share Improve this question edited Aug 25, 2014 at 11:01 Oomph Fortuity 6,19812 gold badges49 silver badges91 bronze badges asked Aug 25, 2014 at 10:56 user3809590user3809590 1851 gold badge3 silver badges13 bronze badges 1
  • along with change listen to keyup, input, paste etc – Arun P Johny Commented Aug 25, 2014 at 11:02
Add a ment  | 

8 Answers 8

Reset to default 4

Use keyup as below

 $("#txt1").on('keyup',function(){
   $("#txt2").val($(this).val())
 });

Just change event for keyup event,

$("#txt1").keyup(function()
{
 $("#txt2").val($(this).val())
});

Try this:

$("#txt1").keyup(function(){
   $("#txt2").val($(this).val())
});

You can also use keyup() of JQuery. It is called when user releases a key on the keyboard.

$("#txtbox").keyup(function(){
   $("#hiddentextbox").val($(this).val())
});

You can use .keydown():

$("#txt").on("keydown", function(){
   $("#hid").val($(this).val());
});

fiddle

Use the input event:

$('#txt1').on('input',function() {
    $('txt2').val( this.value );
});

HTML code

input type = "text" size = "40" id = "inputText"> <input type = "text" size = "40" id = "outputText" value = "" readonly>

jQuery script

$(document).ready(function(){ $('#inputText').keyup(function(){ $('#outputText').val($(this).val()); }); });

Hope this would be helpful to you. Thank you for the useful question.

use .blur as :-

$("#txt1").blur(function(){
   $("#txt2").val($(this).val())
});

OR

$("#txt1").keyup(function(){
  $("#txt2").val($(this).val())
});
发布评论

评论列表(0)

  1. 暂无评论