Tommy Arnold
Tommy Arnold

Reputation: 3389

on change select load another select options using jquery load

Here is my Javascript which is below a select box with the id of "course_name" and a div with an id of "dates"

<script>
$('#course_name').change(function() {
    url = "date_range.php?courseID=".$('#course_name').val();
  $("#dates").load(url)
});

</script>

when i call date_range.php?courseID=1 through my browser it displays the dates but the code above is not loading.

Upvotes: 1

Views: 3360

Answers (1)

Val
Val

Reputation: 17522

url = "date_range.php?courseID="+$('#course_name').val();

or better still,

url = "date_range.php?courseID="+parseInt($('#course_name').val());

the second one will always return a number so it's either 0 (zero) or above, if the #course_name value is a non numeric number it would return zero, otherwise returns the number... this is especially useful when you want to validate the value on the server.

Upvotes: 3

Related Questions