on change select load another select options using jquery load

依然范特西╮ 提交于 2020-01-05 10:13:28

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/5084202/on-change-select-load-another-select-options-using-jquery-load

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!