php - How to copy value input text to multiple/array input text -


i need copy input text array this:

if input "12345":

<input type="text" name="data1"> 

then in text input (array) written "12345"

<? foreach ($countries $data2) { <input type="text" name="$data2['location'][]"> } 

<script language="javascript"> function copy()  {  document.form1.data2.value=document.form1.data1.value } </script> <form action="" method="post" name="form1"> <input type="text" name="data1" onkeyup="copy()"/> <br /><br>  <input type="text" name="data2"> </form> 

no problem...


but if this:

<input type="text" name="data2[]"> <input type="text" name="data2[]"> <input type="text" name="data2[]"> 

or in array php, :

<?php foreach ($countries $data2): ?>     <input type="text" name="<?php echo $data2['location'][] ?>" /> <?php endforeach ?> 

dont work...


it seems need open , close php tags in right place. if name of html input control $data2['location'][], try this:

<?php foreach ($countries $data2): ?>     <input type="text" name="<?php echo $data2['location'][] ?>" /> <?php endforeach ?> 

so, i've closed php mode before , after both loop keywords (the start of loop , end of it). means outside of tags in html mode, name of control, need open tags again. i've chosen use <?php rather <? because latter can turned off on servers. however, fine stick short form if don't mind code not portable.

notice i've used colon more explicit end keyword. popular way of constructing loops in view layer; ordinary controller code, suggest stick ordinary braces.


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -