rdkurth Posted January 29, 2014 Share Posted January 29, 2014 I'm trying to learn jquery and ajax and not doing so well I am trying to pass the id from this dropdown when it is selected to the next ajax script and it is not working. Both scripts pull there data from the same table so if there is a way to do this with one script I would be interested. <select name="customer"id="customer" class="form-control input-sm responsetext" > </select> $( document ).ready(function() { $.ajax({ //create an ajax request to load_page.php type: "GET", url: "customer.php", dataType: "html", //expect html to be returned success: function(response){ $(".responsetext").html(response); //alert(response); } }); }); <?php include("connect.php"); $id = $_SESSION['profile']['id']; echo "<option value=''>SELECT A CUSTOMER</option>"; foreach($db->query("SELECT * FROM customers WHERE pid = '$id'") as $row) { echo "<option value=" . $row['id'] . ">" .$row['name'] . "</option>"; } The above script creates the select box and it works. Now I need the $row['id'] To be picked up by the next script to fill in the input field. <input name="contact" class="form-control input-sm contactresults" id="contact"> $(function() { // document.ready $("#id").on("change", function() { $.ajax({ url: "contact.php", type: "GET", data: { id: $(this).val() }, success: function(data) { $(".contactresults").html(data); } }); }); }); <?php include("connect.php"); $id= $row['id']; echo "<option value=''>SELECT A CUSTOMER</option>"; foreach($db->query("SELECT * FROM customers WHERE id = '$id'") as $row) { echo $row{contact"}; } Quote Link to comment https://forums.phpfreaks.com/topic/285758-pull-data-from-select-box-and-fill-in-a-input-field/ Share on other sites More sharing options...
Skewled Posted March 5, 2014 Share Posted March 5, 2014 Where is $("#id").on("change", function() { located? I don't see any id="id"; anywhere and I suppose this is what is causing your issue, it can't recognize the change because one never occurred. Quote Link to comment https://forums.phpfreaks.com/topic/285758-pull-data-from-select-box-and-fill-in-a-input-field/#findComment-1471533 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.