2012-03-17 58 views
2

下图显示了我的网页部分。我正在开发我的网站使用PHP。onchange刷新特定内容php

enter image description here

如果我选择在draft listmenu在以下字段例如选项的选项,挑1,挑2将改变。我用onchange做了这个。我从onchange获取id,并在select查询中使用该id从数据库中提取细节,并且提取的数据将在下面的列表菜单中被替换。

我需要通过刷新该部分而不是整个页面来完成。有没有可能做到这一点?提前致谢。

回答

2

据,你已经使用jQuery的问题标签。那很棒。

假设第一个选择名称是'draft',其他选择包含在id'picks'的元素中,并且/picks.php?id=X将生成#picks的适当替换:

$('select[name=draft]').change(function() { 
    $.get('/picks.php', {'id': $(this).val()}, function(data) { 
     $('#picks').html(data); 
    }) 
}) 
+0

非常感谢您的努力。 – designersvsoft 2012-03-17 10:17:55

0

是的。这种技术被称为ajax。我建议你看看一个JavaScript库,如jQuery。这将使这个过程变得更容易。您需要的特定jQuery API参考是here

例如你可以使用这样的事情:

// Wait till the page has loaded 
$.ready(function() { 
    // create the on change event 
    $('#draftID').on('change', function() { 
    // get the new information from the server 
    $.ajax({ 
     url: 'document.php?id=' + $('#draftID').val(), 
     success: function(data){ 
     // this code is run when you get the reply; 
     $('#someDivID').html(data); 
     } 
    }); 
    }); 
});