Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I would recommend creating an ID for each of the textboxes and then creating the code onkeyup to update the next field.</p> <p>I assume myvar is part of a while loop. I would create an int that goes up for each cycle through the loop and then create an ID based on that number.</p> <p>Example:</p> <pre><code>&lt;div class="entry-edit"&gt; &lt;div class="entry-edit-head"&gt; &lt;h4 class="icon-head"&gt;&lt;?php echo Mage::helper('mymodule')-&gt;__($value['label']." (".$std['name'].")") ?&gt;&lt;/h4&gt; &lt;/div&gt; &lt;div&gt; &lt;div id="addanswer_form" class="fieldset"&gt; &lt;?php $results = $read-&gt;fetchAll("select * from mytable where standards_id =".$std['standards_id']); $looped = 0; foreach($results as $mykey=&gt;$myvar) { ?&gt; &lt;div class="hor-scroll" style=" margin-bottom: 2px; "&gt; &lt;div style=" width:70px; float:left;"&gt; &lt;label for="name" &gt;&lt;?php echo ucwords($myvar['value']);?&gt; &lt;/label&gt; &lt;/div&gt; &lt;div style=" float:left;"&gt; &lt;input type="text" class="required-entry input-text required-entry" style=" float:left; width:60px;" onkeyup="update_id(&lt;? echo $looped; ?&gt;);" value="" name="size_min[&lt;?php echo $value['dimension_id']."_".$std['standards_id']."_".$myvar['value_id']?&gt;]" id="first_&lt;? echo $looped; ?&gt;"&gt; &lt;/div&gt; &lt;span style="float:left;"&gt; &amp;nbsp;&amp;nbsp;- &amp;nbsp;&amp;nbsp;&lt;/span&gt; &lt;div style=" float:left;"&gt; &lt;input type="text" class="required-entry input-text required-entry" style=" float:left; width:60px;" value="" name="size_max[&lt;?php echo $value['dimension_id']."_".$std['standards_id']."_".$myvar['value_id']?&gt;]" id="second_&lt;? echo $looped; ?&gt;" &gt; &lt;/div&gt; &lt;/div&gt; &lt;?php $looped++; } // end of foreach loop for standard values ?&gt; &lt;/div&gt; </code></pre> <p>Then create this javascript function:</p> <pre><code>&lt;script&gt; function update_id(id){ next = id+1; if($("#first_"+next).length){ //if the next first checkbox exists, set the value from the previous second checkbox. $("#first_"+next).val($("#second_"+id).val()); } } &lt;/script&gt; </code></pre> <p>Notice the onkeyup method and the updated id's along with the <code>$looped</code> variable.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload