Postingan lainnya
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
2 Jawaban:
<div>Bisa pakai javascript, contohnya :</div><pre><!DOCTYPE html> <html> <body>
<select id="combobox" onchange="myFunction()"> <option value="Audi">Audi</option> <option value="BMW">BMW</option> <option value="Mercedes">Mercedes</option> <option value="Volvo">Volvo</option> </select>
<p id="textbox">Audi</p>
<script> function myFunction() { var x = document.getElementById("combobox").value; document.getElementById("textbox").innerHTML = x; } </script>
</body> </html></pre><div><br>Semoga membantu</div>
<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'])->name('penandatangan.getlist');<br><br><strong>CONTROLLER</strong><br> public function getlist($id){<br> $fill=User::where('id', $id)->pluck('nmlgkp');<br> return Response::json(['success'=>true, 'info'=>$fill]);<br> }<br><br><strong>JAVASCRIPT</strong><br><script><br> $("#nmlgkp").change(function() {<br> $.ajax({<br> url: 'penandatangan.getlist/' + $(this).val(),<br> type: 'GET',<br> data: {},<br> success: function(data) {<br> if (data.success == true) {<br> $("#nip").value = data.nip;<br> } else {<br> alert('Data tidak ditemukan');<br> }<br><br> },<br> error: function(jqXHR, textStatus, errorThrown) {}<br> });<br> });<br> </script><br><br><strong>VIEW</strong><br> <form action="#" method="POST" class="row g-12"><br> @csrf<br><br> <div class="col-md-6 mb-3"><br> <label for="nmlgkp" class="form-label">Nama Penandatangan</label><br> <select name="nmlgkp" id="nmlgkp" class="form-control" required autofocus><br> <option value="">== Pilih Nama ==</option><br> @foreach($users['data'] as $user)<br> <option value="{{ $user->id }}">{{ $user->nmlgkp }}</option><br> @endforeach<br> </select><br> </div><br><br> <div class="col-md-6 mb-3"><br> <label for="nip" class="form-label">NIP</label><br> <input type="text" class="form-control" id="nip" name="nip" readonly><br> </div><br><br> <div class="col-md-12 mb-3"><br> <label for="jbtn" class="form-label">Jabatan</label><br> <input type="text" class="form-control" id="jbtn" name="jbtn" readonly><br> </div><br><br> <div class="col-md-12"><br> <button type="submit" class="btn btn-primary">Simpan</button><br> </div><br> </form><br><br>mohon bantuannya para master laravel sekalian.... Terimakasih</div>