开发者

dropdownlist problem with the use of ajax and php

I have some problem with on of the pages of a project. I have 1 drop down on top o开发者_如何学Gof the page , and in that list the items are - today , last week. Now according to that list item-value , below that drop down list records should be displayed from the database.

dummy code:

if today
then
records with current date should be displayed 

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


First drop-down on which 2nd drop-down will be shown -

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

Container of Table - Records

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

Script for update Table of Records -

<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>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜