我不是在这里发布完整的代码,但我想知道如何基于下拉列表检索checboxes中的数据。我有一个用户下拉列表,以及复选框中的页面数据。如何从Ajax/Jquery的下拉列表中获取复选框中的数据
假设表user
有两列(user_id
,user
)和pages
有三列(page_id
,user_id
,title
)。
我希望这些cheboxes根据选定的用户自动检查/取消选中,而无需刷新页面。假如我是获取用户的
echo '<select name="user_id">';
echo '<option value="">Select User</option>';
$sql = "SELECT * from users";
$res = mysql_query($sql);
while($row = mysql_fetch_assoc($res)) {
$uid = $row['user_id'];
$user = $row['user'];
echo '<option value="'.$uid.'">'.$user.'</option>';
}
echo '</select>';
和数据选择的用户的基础上复选框(确保user_id
在IF condition
相比,但不是在查询)
$user_id = $_POST['user_id']; //selected user from list
$query = "SELECT * from pages";
$result = mysql_query($query);
while($rowPage = mysql_fetch_assoc($result)) {
$upid = $rowPage['user_id'];
$pid = $rowPage['page_id'];
$title = $rowPage['title'];
if($upid == $user_id) {
echo '<input type="checkbox" name="userPages[]" value="'.$pid.'" checked="checked"> '.$title;
} else {
echo '<input type="checkbox" name="userPages[]" value="'.$pid.'"> '.$title;
}
}
怎么可能在阿贾克斯/ Jquery我的意思是没有刷新页面。 希望你明白我的意思。 感谢
只需用您从ajax调用中检索到的'select'元素替换它并完成它呢? – dbf
感谢您的回复,但主要的是我需要的是ajax代码,我没有ajax的知识:( – Bheem
err ..然后开始阅读关于ajax的做法?最快和最简单的方法是使用像[jQuery] (http://www.jquery.com)的使用许多[ajax](http://api.jquery.com/category/ajax/)方法之一 – dbf