Jump to content

Recommended Posts

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"};
}
  • 1 month later...
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.