javascript - How to Reflect input of a textbox into another textbox -


this code reflect text of textbox1 textbox called textbox1a on keyup event. separate them same background. show each result specific input. when write in first text box repeat text others. how can separate them? here code :

$("input[type=text]").keyup(function(){     var classname = $(this).attr('class').replace('valueenter','').trim();     $("."+classname).val($(this).val());  });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>  <div class="first">  textbox 1a : <input type="text" class="textbox1 valueenter" style="background:#ccc;"/><br/>  textbox 1b : <input type="text" class="textbox1 valueenter" style="background:pink;"/> <br/>   textbox 2 : <input type="text" class="textbox2 valueenter"/>  </div>  <br/>  <div class="second">  show text 1a : <input type="text" class="textbox1" style="background:#ccc;"/> <br/>   show text 1b : <input type="text" class="textbox1" style="background:pink;"/> <br/>  show text2 : <input type="text" class="textbox2"/>  </div>

you can use .index() here find index of input inside .first , use .eq() change value input @ index inside .second

$("input[type=text]").keyup(function(){     var index = $('.first .textbox1').index(this);     var classname = $(this).attr('class').replace('valueenter','').trim();     $(".second ."+classname).eq(index).val($(this).val());  });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>  <div class="first">  textbox 1a : <input type="text" class="textbox1 valueenter" style="background:#ccc;"/><br/>  textbox 1b : <input type="text" class="textbox1 valueenter" style="background:pink;"/> <br/>   textbox 2 : <input type="text" class="textbox2 valueenter"/>  </div>  <br/>  <div class="second">  show text 1a : <input type="text" class="textbox1" style="background:#ccc;"/> <br/>   show text 1b : <input type="text" class="textbox1" style="background:pink;"/> <br/>  show text2 : <input type="text" class="textbox2"/>  </div>


Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -