开发者

How to type in two text fields simulatenously (jQuery)

I was unsuccessful in finding a jQuery plugin t开发者_运维百科hat allowed me to write in two inputs simultaneously.

I'm trying to write a normal title in one field, and at the same time type in another input write the same text without special characters or spaces.

e.g.

Input 1: This is my Title!

Input 2: ThisIsMyTitle


on keyup copy input value from current input into 2nd input, no plugin is required.

$("input#first").keyup(function(e){
  var val = $(this).val();
  val = val.replace(/[^\w]+/g, "");
  $("input#second").val(val);
});

something like that


$("#myTextInput").keyup(function() {
    var text = $(this).val();
    text = processText(text);
    $("#secondTextField").val(text);
});


jQuery("input1").keyup(function() {
  jQuery("input2").val(removeWhiteSpace(jQuery("input1")));
} 

(pseudo code)


​var a = jQuery('input#a'),
    b = jQuery('input#b');

a.keyup(function(){
    b.val(this.value.replace(/[^\w]/g, ''));
});​​​​​​​


Full code, it will get only letters and numbers and display on the input2 without anything else.

$("#input1").keyup
(
    function ()
    {
        $("#input2").val
        (
            $(this).val().match(/[a-z]|[0-9]/gi).join("")
        );
    }
);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜