使用ajax和php的dropdownlist问题

时间:2011-04-19 09:56:24

标签: php mysql ajax

我对项目的页面有一些问题。 我在页面顶部有一个下拉列表,在该列表中的项目是 - 今天,上周。 现在根据该列表项值,下面的下拉列表记录应该从数据库中显示。

虚拟代码:

if today
then
records with current date should be displayed 

and if last week
then
records with date in last week should be displayed

1 个答案:

答案 0 :(得分:0)

第一个下拉列表将显示第二个下拉列表 -

<select name="day" onchange="itemsToShowFor();">
<option value="today">Today</option>
<option value="last_week">Last Week</option>
</select>

表格容器 - 记录

<div id="records"></div>

更新记录表的脚本 -

<script type="text/javascript">
$(document).ready(function(){    
    itemsToShowFor();
});

function itemsToShowFor(){
  var itemToShowFor = $("select:[name=day]").val();
  $.ajax({
      type:'POST',
      url:URL_TO_GET_ITEMS,
      data:[day:itemToShowFor ],
      success:function(list){
          $("#records").html(list); // list will contain records formatted with HTML 
      }
      });
}

</script>