javascript - How to get selected combobox value and load its corresponding data in html form -
i have combobox loads value data base. want when user select value combobox form should load corresponding values database html form. here code trying:
<div class="col-lg-6" style="display:none" id="c" > <form id="aa" action="" method="post" > <br><br><br> <select name="id" id="id" class="span2" style=" width:150px;" onchange="this.form.submit();"> <?php $servername = "localhost"; $username = "root"; $password = ""; $dbname = "valet"; // create connection $conn = mysqli_connect($servername, $username, $password, $dbname); // check connection if (!$conn) { die("connection failed: " . mysqli_connect_error()); } $arr = array(); $sql = "select id tbl_user "; $result = mysqli_query($conn, $sql); // echo "user name=" . $row["name"]. "<br>"; ?> <option value="">-select user-</option> <?php if (mysqli_num_rows($result) > 0) { // output data of each row while($row = mysqli_fetch_assoc($result)) { $arr[] = $row; } foreach($arr $key => $row){ echo "<option value='".$row["id"]."'>".$row["id"]."</option>"; $globals['a'] = $row["first_name"]; $globals['b'] = $row["last_name"]; $globals['c'] = $row["phone"]; $globals['d'] = $row["company_id"]; $globals['e'] = $row["register_on"]; } } else { echo "error: " . $sql . "<br>" . mysqli_error($conn); header('location: webservices.php'); } mysqli_close($conn); ?> </select> <br><br><br> <input type="text" id="first_name" value="<?php $globals['a'] ?>" name="first_name" style="width: 460px;height: 50px;overflow: hidden;" placeholder="first name*"> <br><br><br><br> <input type="text" id="last_name" value="<?php $globals['b'] ?>" name="last_name" style="width: 460px;height: 50px;overflow: hidden;" placeholder="last name*"> <br><br><br><br> <input type="text" id="phone" value="<?php $globals['c'] ?>" name="phone" style="width: 460px;height: 50px;overflow: hidden;" placeholder="phone*"> <br><br><br><br> <input type="text" id="company_id" value="<?php $globals['d'] ?>" name="company_id" style="width: 460px;height: 50px;overflow: hidden;" placeholder="company id*"> <br><br><br><br> <input type="text" id="register_on" value="<?php $globals['e'] ?>" name="register_on" style="width: 460px;height: 50px;overflow: hidden;" placeholder="register on*"> <br><br><br><br> <button name="edituser" id="edituser" type="submit" style="border:0;width:100px;margin-left: 45px;" > <img src="images/save.png" alt=""> </button> <button type="submit" style="border:0;width:100px;margin-left: 75px;"> <img src="images/cancel.png" alt=""> </button> </form> </div>
please me how can accomplish task?
you can use jquery this. record marco mura
did give solution problem. didn't want research problem , solve after solution given you.
$("#id").change(function(){ $.post("www.example.com?val=" + $(this).val(),function(response){ $("#mydiv").html(response); }) })
Comments
Post a Comment