javascript - How to get value from one textbox and assign to next coming textbox -


i trying textbox value , trying assign next coming text field.enter image description here

just in image ,when try add value second textfield (like 260 ) fill next (kashif first textfield in example) field previous field value.this work after second field entry , one.nothing first. name , id dynamically generated first size_min[1_1_0]( 240) , size_max[1_1_0] (for 260).i confuse due dynamic ids of field. html code :

    <div class="entry-edit">     <div class="entry-edit-head">      <h4 class="icon-head"><?php echo mage::helper('mymodule')->__($value['label']." (".$std['name'].")") ?></h4>      </div>     <div>      <div id="addanswer_form" class="fieldset">             <?php      $results = $read->fetchall("select *  mytable standards_id =".$std['standards_id']);   foreach($results $mykey=>$myvar)   { ?>     <div class="hor-scroll" style=" margin-bottom: 2px; ">     <div style=" width:70px; float:left;">         <label for="name" ><?php echo ucwords($myvar['value']);?> </label>         </div>         <div style=" float:left;"> <input type="text" class="required-entry input-text required-entry" style=" float:left; width:60px;"  value="" name="size_min[<?php echo $value['dimension_id']."_".$std['standards_id']."_".$myvar['value_id']?>]" id="size_min[<?php echo $value['dimension_id']."_".$std['standards_id']."_".$myvar['value_id']?>]">  </div> <span style="float:left;"> &nbsp;&nbsp;- &nbsp;&nbsp;</span>   <div style=" float:left;"> <input type="text" class="required-entry input-text required-entry" style=" float:left; width:60px;"  value="" name="size_max[<?php echo $value['dimension_id']."_".$std['standards_id']."_".$myvar['value_id']?>]" id="size_max[<?php echo $value['dimension_id']."_".$std['standards_id']."_".$myvar['value_id']?>]" >  </div>  </div> <?php   } // end of foreach loop standard values           ?> </div> 

this output in html formate:

<div class="fieldset" id="addanswer_form">     <div style=" margin-bottom: 2px; " class="hor-scroll">         <div style=" width:70px; float:left;">             <label for="name">neemh</label>         </div>         <div style=" float:left;">             <input type="text" id="size_min[1_1_7]" name="size_min[1_1_7]" value="" style=" float:left; width:60px;" class="required-entry input-text required-entry">         </div> <span style="float:left;"> &nbsp;&nbsp;- &nbsp;&nbsp;</span>          <div style=" float:left;">             <input type="text" id="size_max[1_1_7]" name="size_max[1_1_7]" value="" style=" float:left; width:60px;" class="required-entry input-text required-entry">         </div>     </div>     <div style=" margin-bottom: 2px; " class="hor-scroll">         <div style=" width:70px; float:left;">             <label for="name">kashif</label>         </div>         <div style=" float:left;">             <input type="text" id="size_min[1_1_8]" name="size_min[1_1_8]" value="" style=" float:left; width:60px;" class="required-entry input-text required-entry">         </div> <span style="float:left;"> &nbsp;&nbsp;- &nbsp;&nbsp;</span>          <div style=" float:left;">             <input type="text" id="size_max[1_1_8]" name="size_max[1_1_8]" value="" style=" float:left; width:60px;" class="required-entry input-text required-entry">         </div>     </div>     <div style=" margin-bottom: 2px; " class="hor-scroll">         <div style=" width:70px; float:left;">             <label for="name">shamma</label>         </div>         <div style=" float:left;">             <input type="text" id="size_min[1_1_10]" name="size_min[1_1_10]" value="" style=" float:left; width:60px;" class="required-entry input-text required-entry">         </div> <span style="float:left;"> &nbsp;&nbsp;- &nbsp;&nbsp;</span>          <div style=" float:left;">             <input type="text" id="size_max[1_1_10]" name="size_max[1_1_10]" value="" style=" float:left; width:60px;" class="required-entry input-text required-entry">         </div>     </div> </div> </div> 

you use following dom traversal code:

$('.hor-scroll div:nth-of-type(3) input:text').on('input', function(e) {     $(this).closest('.hor-scroll').next().find('input:text:eq(0)').val(this.value); }); 

that selects <input type="text"/> element third <div> element each of <div class="hor-scroll"> elements, second textbox in each row. then, relative textbox, finds first textbox of next row, , sets value.

example jsfiddle


Comments