views:

32

answers:

5

I was unsuccessful in finding a jQuery plugin that 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

+2  A: 

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

mkoryak
May as well use `this.value` (much cheaper than `$(this).val()`). Also, you should cache `$("input#second")`.
J-P
something like that == not optimal. i actually wrote it while on a support call with lenovo.
mkoryak
A: 
jQuery("input1").keyup(function() {
  jQuery("input2").val(removeWhiteSpace(jQuery("input1")));
} 

(pseudo code)

Jaroslav Moravec
A: 
$("#myTextInput").keyup(function() {
    var text = $(this).val();
    text = processText(text);
    $("#secondTextField").val(text);
});
David Wolever
A: 
​var a = jQuery('input#a'),
    b = jQuery('input#b');

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

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("")
        );
    }
);
BrunoLM