subendi Posted December 13, 2022 Share Posted December 13, 2022 (edited) file menuUser.php !DOCTYPE html> <html> <head> </head> <body> <?php require 'vendor/autoload.php'; $conn = new MongoDB\Client(); $db = $conn->cucian1; $collection = $db->cabang_kota; $datacabangkota=$collection->find(); ?> <select name="cabangKota" onchange="getId(this.value);">> <?php foreach($datacabangkota as $cabangkota){?> <option value="<?php $id= $cabangkota["_id"]; $kota= $cabangkota["cabang"]; echo $id; ?>"><?php echo $kota;} ?></option> </select> <select name="cabangDesa" id="cabangDesa"></select> <script src="https://code.jquery.com/jquery-3.1.1.js" integrity="sha256-16cdPddA6VdVInumRGo6IbivbERE8p7CQR3HzTBuELA=" crossorigin="anonymous"> </script> <script> function getId(val){ $.ajax({ type: "POST", url: "cabangDesa.php", data: "cid="+val, success: function(data){ $("#cabangDesa").html(data); } }); } </script> </body> </html> file cabangDesa.php <?php require 'vendor/autoload.php'; $conn = new MongoDB\Client(); $db = $conn->cucian1; $collection = $db->cabang_desa; $cid = $_POST["cid"]; $query = array("cabang_kota_id"=>$cid); $datacabangDesa=$collection->find($query); ?> <option value="">Select State</option> <?php foreach($datacabangDesa as $cabangdesa){?> <option value="<?php $id= $cabangdesa["_id"]; $desa= $cabangdesa["cabang"]; echo $id; ?>"><?php echo $desa;}?></option> The first category of dropdown is working fine but I am wondering why my 2nd dropdown is not working. I just cant trace any error in the code and yet this is happening. Edited December 13, 2022 by subendi Quote Link to comment https://forums.phpfreaks.com/topic/315642-dropdown-dynamic-using-php-and-mongodb/ Share on other sites More sharing options...
ginerjm Posted December 13, 2022 Share Posted December 13, 2022 First let's be sure that you have php error checking enabled. Add this to the beginning of your php code error_reporting(E_ALL); ini_set('display_errors', '1'); That will help. Tell us what you get. Quote Link to comment https://forums.phpfreaks.com/topic/315642-dropdown-dynamic-using-php-and-mongodb/#findComment-1603509 Share on other sites More sharing options...
subendi Posted December 16, 2022 Author Share Posted December 16, 2022 no changes Quote Link to comment https://forums.phpfreaks.com/topic/315642-dropdown-dynamic-using-php-and-mongodb/#findComment-1603575 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.