使用javascript动态获取复选框值
我们已使用以下代码列出具有电子邮件id的员工使用javascript动态获取复选框值,javascript,php,Javascript,Php,我们已使用以下代码列出具有电子邮件id的员工 <tbody> <?php $sqlquery = mysql_query("select * FROM employee"); while($row=mysql_fetch_object($sqlquery)){ ?> <tr class="gradeA"> <td><input type="checkbox" name
<tbody>
<?php
$sqlquery = mysql_query("select * FROM employee");
while($row=mysql_fetch_object($sqlquery)){
?>
<tr class="gradeA">
<td><input type="checkbox" name="eid" value="<?php echo $row->emailid;?>" onclick="send_email_form_test()"><?php echo $row->name;?></td>
</tr>
<?php }?>
</tbody>
单击复选框后,电子邮件ID将显示在文本区域字段中。当我转到员工列表的第二页时,我无法访问文本区域字段,它将在第二页为空
<div>
<label for="required">TO</label>
<textarea name="to" cols="5" rows="10"></textarea>
</div>
<div>
<label for="email">Subject</label>
<input type="text" size="80" id="subject" name="subject" >
<input type="submit" name="submit" value="submit">
</div>
当我点击复选框时,如何添加和删除逗号分隔的电子邮件ID。我对何时进入分页的下一页有疑问您可以将“this”参数作为onclick=send\u email\u form\u testthis>添加到Javascript函数中,然后您将获得单击的复选框对象。然后您将能够检索单击复选框的值我没有测试它,但我认为这就是您可以从所有页面收集电子邮件的方式
<?php
//...
echo '<script>window.tablePage = ', $paginator->currentPage, ';</script>';
?>
<script type="application/javascript">
//...
pageSelected = selected.join(',');
//get emails selected on other pages
allSelected = JSON.parse(localStorage.getItem('emails'));
//add currently selected emails
allSelected[tablePage] = pageSelected;
localStorage.setItem('emails', JSON.stringify(allSelected));
//output emails from all pages
document.getElementById("to").value = allSelected.join(',');
//...
</script>
JSON库在这里:使用onclick-on复选框将执行函数,无论它是选中的还是未选中的。在末尾添加指定了onclick的按钮。另外,将复选框命名为name=eid[]如果您使用PHP paginator,您可能需要通过AJAX下载页面并在本地分页,或者在切换页面之前使用AJAX将选定的电子邮件发送到服务器。当PHP每次单击都生成新页面时,您不能在页面上本地存储某些内容。
<?php
//...
echo '<script>window.tablePage = ', $paginator->currentPage, ';</script>';
?>
<script type="application/javascript">
//...
pageSelected = selected.join(',');
//get emails selected on other pages
allSelected = JSON.parse(localStorage.getItem('emails'));
//add currently selected emails
allSelected[tablePage] = pageSelected;
localStorage.setItem('emails', JSON.stringify(allSelected));
//output emails from all pages
document.getElementById("to").value = allSelected.join(',');
//...
</script>