How to write a program on Javascript

FratBro23
Category:
Programming
Price: $15 USD

Question description

I have two codes below to test what I am trying to do. Every thing in the code is working except I can not get it to fill the input field at the bottom of the first script. After two day of tinkering I cant figure out way. When I run the code and look at the results in Developer tools and it show the data being created but it will not place it in the input field . I have a demo set up if you need to look at it. I am still learning jquery and it is driving me crazy



<html>

<head>

    <script type="text/javascript" src="js/jquery-1.11.0.min.js"></script>

    <script type="text/javascript" src="js/jquery-ui-1.10.4.custom.min.js"></script>

   <script type="text/javascript">

     

    $(document).ready(function () {

    $("#customer").change(function () {

        var cid = $("#customer").val();

         $.ajax({

            type: "POST",

            url: "contact.php",

            data: "cid=" + cid,

            success: function (data) {

                var options = [];

                //$.each(data[cid - 1], function () {

                $.each(data, function () {

                    options.push('<option value="' + this.id + '">' + this.name + '</option>');

                });

                $(".contact").html(options.join(""));

            }

        });

    });

});

    </script>

 </head>

 <body>

    Customer:

    <select name="customer" id="customer">

      <option>-Select a Customer-</option>

    <?php 

   

  include("connect.php");

    $id = $_SESSION['profile']['id']; 

   foreach($db->query("SELECT * FROM customers WHERE pid = '$id'") as $row) {

        echo "<option value=" . $row['id'] . ">" . $row['name'] . "</option>";

}

        ?>

    </select>

Contact:

<input type="text" value="" id="contact"/>

  </body>

</html>



<?php

include("connect.php");

$cid = $_POST["cid"];

foreach($db->query("SELECT contact FROM customers WHERE id = '$cid'") as $row) {

     }

 echo $row['contact'];

   


Studypool has helped 1,244,100 students
Ask your homework questions. Receive quality answers!

Type your question here (or upload an image)

1822 tutors are online

Brown University





1271 Tutors

California Institute of Technology




2131 Tutors

Carnegie Mellon University




982 Tutors

Columbia University





1256 Tutors

Dartmouth University





2113 Tutors

Emory University





2279 Tutors

Harvard University





599 Tutors

Massachusetts Institute of Technology



2319 Tutors

New York University





1645 Tutors

Notre Dam University





1911 Tutors

Oklahoma University





2122 Tutors

Pennsylvania State University





932 Tutors

Princeton University





1211 Tutors

Stanford University





983 Tutors

University of California





1282 Tutors

Oxford University





123 Tutors

Yale University





2325 Tutors