0

I am trying to use jQuery methods for ajax to create a dropdown menu. Using this jQuery code:

JAVASCRIPT:

<SCRIPT>
$("select[name='carid']").on("change", function() {
  $.post(
    "execute.php",
    { carid: $("#carid").val() },
    function(data) {
      $("available").append(data);
    }
  );
});
</SCRIPT>

execute.php :

<?php
$carid = $_POST['carid'];
$result = mysql_query("SELECT mID, mName FROM Model WHERE cID = '$carid' ");
$select = "<select>";

while ($row = mysql_fetch_array($result))
{
    $mID = $row['mID'];
    $mName = $row['mName'];
    $select+= "<option value='".$mID."'>" .$mName. "</option>";
}
$select += "</select>"
echo $select;

?>

Unfortunately I am getting this error on loading in console event.returnValue is deprecated. Please use the standard event.preventDefault() instead. Any help is much appreciated.

Amir
  • 1,328
  • 2
  • 13
  • 27

3 Answers3

0

replace this line and try again

 $select += "</select>";

and if $("available").append(data); in this line available is class than use .available and if it an id than use #available

Bhupendra
  • 248
  • 2
  • 7
0

The problem is here I think:

$("available").append(data);

What is available here? It won't append data any where.

Since you haven't shown us your html so assuming that it may be an element with id or class set to available so it should be $(".available").append(data); or $("available").append(data); depending upon the element to which you want to append.

UPDATE

since you specified that it's a <div id="available"> so try $("#available").append(data); instead of $("available").append(data);

Here is the complete script

<script>
$("select[name='carid']").on("change", function() {
  $.post(
    "execute.php",
    { carid: $("#carid").val() },
    function(data) {
      console.log(data); // just for testing
      $("#available").append(data);
    }
  );
});
</script>

If that doesn't work either, check your console and post the output here.

Kamran Ahmed
  • 11,809
  • 23
  • 69
  • 101
0

See here

event.returnValue is deprecated. Please use the standard event.preventDefault() instead

This is just a warning and can be safely ignored for the time being. It has been changed in jQuery 1.11

Community
  • 1
  • 1
user888734
  • 3,797
  • 5
  • 36
  • 67