Prashant Sharma Prashant Sharma - 1 year ago 65
HTML Question

Copy only text from one textbox to another textbox using javascipt

I want to copy value of one textbox to another textbox using javascript. When user type value in first textbox then it should automatically copy into another textbox,

Now what my requirement is:
If user type text only then it should copy into another textbox.
If user type numbers then it should not be copied into another one.

Answer Source

var firstText=document.getElementById('firstText'),
    secondtext=document.getElementById('secondText');
firstText.addEventListener('input',function(){
  var val=this.value;
  secondtext.value=val.replace(/[0-9]/g, "");
});
<input id="firstText" type="text"/>
<input id="secondText" type="text"/>