Tolong pilih kategori sesuai, jenis posting (pertanyaan atau bukan) dan sertakan tag/topik yang sesuai misal komputer, php, mysql, dll.
Promosi atau posting tidak pada tempatnya akan kami hapus.
Mencantumkan kode program di posting Anda, tolong ikuti aturan yang sesuai, baca http://diskusiweb.com/discussion/39204/aturan-cara-menyisipkan-kode-program-di-diskusiweb

Baca cara posting gambar/image di post Anda: http://www.diskusiweb.com/discussion/47345/cara-menyisipkan-menyertakan-image-pada-posting/p1

Copy value input text ke array input text

Mohon bantuannya, bagaimana caranya untuk meng-copy value dari satu input text, agar tertulis juga pada multiple/array input text lainnya. contohnya:
<pre lang="javascript">
<span class="tag">&lt;script</span><span class="pln"> </span><span class="atn">language</span><span class="pun">=</span><span class="atv">"javascript"</span><span class="tag">&gt;</span><span class="pln">
</span><span class="kwd">function</span><span class="pln"> copy</span><span class="pun">()</span><span class="pln">
</span><span class="pun">{</span><span class="pln">

document</span><span class="pun">.</span><span class="pln">form1</span><span class="pun">.</span><span class="pln">data2</span><span class="pun">.</span><span class="pln">value</span><span class="pun">=</span><span class="pln">document</span><span class="pun">.</span><span class="pln">form1</span><span class="pun">.</span><span class="pln">data1</span><span class="pun">.</span><span class="pln">value
</span><span class="pun">}</span><span class="pln">
</span><span class="tag">&lt;/script&gt;</span><span class="pln">
</span><span class="tag">&lt;form</span><span class="pln"> </span><span class="atn">action</span><span class="pun">=</span><span class="atv">""</span><span class="pln"> </span><span class="atn">method</span><span class="pun">=</span><span class="atv">"post"</span><span class="pln"> </span><span class="atn">name</span><span class="pun">=</span><span class="atv">"form1"</span><span class="tag">&gt;</span><span class="pln">
</span><span class="tag">&lt;input</span><span class="pln"> </span><span class="atn">type</span><span class="pun">=</span><span class="atv">"text"</span><span class="pln"> </span><span class="atn">name</span><span class="pun">=</span><span class="atv">"data1"</span><span class="pln"> </span><span class="atn">onKeyUp</span><span class="pun">=</span><span class="atv">"</span><span class="pln">copy</span><span class="pun">()</span><span class="atv">"</span><span class="tag">/&gt;</span><span class="pln">
</span><span class="tag">&lt;br</span><span class="pln"> </span><span class="tag">/&gt;&lt;br&gt;</span><span class="pln">

</span><span class="tag">&lt;input</span><span class="pln"> </span><span class="atn">type</span><span class="pun">=</span><span class="atv">"text"</span><span class="pln"> </span><span class="atn">name</span><span class="pun">=</span><span class="atv">"data2"</span><span class="tag">&gt;</span><span class="pln">
</span><span class="tag">&lt;/form&gt;<br>&lt;/pre&gt;<br><br>kode diatas, bisa bekerja hanya untuk satu input text, tapi tidak bisa untuk array seperti ini:<br></span>

<pre lang="php">
<span class="pun">&lt;?</span><span class="pln">php </span><span class="kwd">foreach</span><span class="pln"> </span><span class="pun">(</span><span class="pln">$countries </span><span class="kwd">as</span><span class="pln"> $data2</span><span class="pun">):</span><span class="pln"> </span><span class="pun">?&gt;</span><span class="pln">
&lt;input type="text" name="</span><span class="pun">&lt;?</span><span class="pln">php echo $data2</span><span class="pun">[</span><span class="str">'location'</span><span class="pun">][]</span><span class="pln"> </span><span class="pun">?&gt;</span><span class="pln">" /&gt;
</span><span class="pun">&lt;?</span><span class="pln">php endforeach </span><span class="pun">?&gt;</span>

<span class="tag">&lt;/pre&gt;</span>

Tanggapan

Sign In or Register to comment.