menampilkan data ditextboxt melalui combobox dilaravel 8

selamat siang....

saya masih newbie... bagaimana cara menampilkan data ditextboxt secara otomatis berdasarkan pilihan di combo/dropdown pada laravel 8... makasih

avatar bgpoels
@bgpoels

35 Kontribusi 2 Poin

Diperbarui 3 tahun yang lalu

2 Jawaban:

<div>Bisa pakai javascript, contohnya :</div><pre>&lt;!DOCTYPE html&gt; &lt;html&gt; &lt;body&gt;

&lt;select id="combobox" onchange="myFunction()"&gt; &lt;option value="Audi"&gt;Audi&lt;/option&gt; &lt;option value="BMW"&gt;BMW&lt;/option&gt; &lt;option value="Mercedes"&gt;Mercedes&lt;/option&gt; &lt;option value="Volvo"&gt;Volvo&lt;/option&gt; &lt;/select&gt;

&lt;p id="textbox"&gt;Audi&lt;/p&gt;

&lt;script&gt; function myFunction() { var x = document.getElementById("combobox").value; document.getElementById("textbox").innerHTML = x; } &lt;/script&gt;

&lt;/body&gt; &lt;/html&gt;</pre><div><br>Semoga membantu</div>

avatar syahid246
@syahid246

70 Kontribusi 160 Poin

Dipost 3 tahun yang lalu

<div>saya sudah coba namun belum berhasil... berikut ini script lengkap saya<br><br><strong>ROUTE</strong><br>Route::get('penandatangan.getlist/{id}', [PenandatanganController::class, 'getlist'])-&gt;name('penandatangan.getlist');<br><br><strong>CONTROLLER</strong><br> public function getlist($id){<br>&nbsp; &nbsp; &nbsp; &nbsp; $fill=User::where('id', $id)-&gt;pluck('nmlgkp');<br>&nbsp; &nbsp; &nbsp; &nbsp; return Response::json(['success'=&gt;true, 'info'=&gt;$fill]);<br>&nbsp; &nbsp; }<br><br><strong>JAVASCRIPT</strong><br>&lt;script&gt;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $("#nmlgkp").change(function() {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $.ajax({<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; url: 'penandatangan.getlist/' + $(this).val(),<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; type: 'GET',<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; data: {},<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; success: function(data) {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (data.success == true) {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $("#nip").value = data.nip;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; } else {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; alert('Data tidak ditemukan');<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; },<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; error: function(jqXHR, textStatus, errorThrown) {}<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; });<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; });<br>&nbsp; &nbsp; &nbsp; &nbsp; &lt;/script&gt;<br><br><strong>VIEW</strong><br> &lt;form action="#" method="POST" class="row g-12"&gt;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; @csrf<br><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;div class="col-md-6 mb-3"&gt;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;label for="nmlgkp" class="form-label"&gt;Nama Penandatangan&lt;/label&gt;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;select name="nmlgkp" id="nmlgkp" class="form-control" required autofocus&gt;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;option value=""&gt;== Pilih Nama ==&lt;/option&gt;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; @foreach($users['data'] as $user)<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;option value="{{ $user-&gt;id }}"&gt;{{ $user-&gt;nmlgkp }}&lt;/option&gt;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; @endforeach<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;/select&gt;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;/div&gt;<br><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;div class="col-md-6 mb-3"&gt;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;label for="nip" class="form-label"&gt;NIP&lt;/label&gt;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;input type="text" class="form-control" id="nip" name="nip" readonly&gt;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;/div&gt;<br><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;div class="col-md-12 mb-3"&gt;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;label for="jbtn" class="form-label"&gt;Jabatan&lt;/label&gt;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;input type="text" class="form-control" id="jbtn" name="jbtn" readonly&gt;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;/div&gt;<br><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;div class="col-md-12"&gt;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;button type="submit" class="btn btn-primary"&gt;Simpan&lt;/button&gt;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&lt;/div&gt;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;/form&gt;<br><br>mohon bantuannya para master laravel sekalian.... Terimakasih</div>

avatar bgpoels
@bgpoels

35 Kontribusi 2 Poin

Dipost 3 tahun yang lalu

Login untuk ikut Jawaban