复选框的顺序顺序选择的PHP [英] Sequential Order of Checkboxes Selected PHP

查看:127
本文介绍了复选框的顺序顺序选择的PHP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前,我的HTML代码是:

 < form id =querymethod =postaction =search.php> 
< input type =checkboxname =col_list []value =host> host< / input>
< input type =checkboxname =col_list []value =atom_name> atom_name< / input>
...
< input type =submit> / input>
< / form>



  $ columns = $ _POST [col_list]; 

$

解决方案

有什么办法可以得到被选中的复选框的顺序?

您需要添加一些javascript才能获取该信息。

 < input type =hidden =order/><! - 在表单内 - > 

是使用jQuery的例子:

  $('[name * =col_list]' 
if($(this).prop('checked')){
$('[name =order]' .val()+','+ $(this).val())
}
});

这应该很好地与一个警告:



如果用户取消选中然后re-ckecks一个复选框,它将被添加到

 ,请执行以下操作: host,atom_name 

编辑 $ b

修正了一些拼写错误,这里有一个 小提琴


At the moment, my html code is:

<form id = "query" method = "post" action = "search.php">
     <input type = "checkbox" name = "col_list[]" value = "host">host</input>
     <input type = "checkbox" name = "col_list[]" value = "atom_name>atom_name</input>
     …
     <input type = "submit">Submit</input>
</form>

And my php code:

 $columns = $_POST["col_list"];

Is there any way is which I can get the sequence in which the checkboxes where checked?

解决方案

you'd need to add a some javascript to get that info.

<input type="hidden" name="order"/> <!-- goes inside the form -->

Here is an examply using jQuery:

$('[name*="col_list"]').change(function(){
   if ($(this).prop('checked')){
       $('[name="order"]').val($('[name="order"]').val()+','+$(this).val())
    }
});

This should work fairly well with one caveat:

If the user un-checks then re-ckecks a checkbox it will be added to order twice.

order should result in something like:

,host,atom_name

Edit

Fixed some typos and here is a fiddle

这篇关于复选框的顺序顺序选择的PHP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆