处理多个复选框 [英] Handling Multiple check boxes

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

问题描述

我有一个PHP生成的页面,显示X许多记录。每条记录都有

前面的复选框。用户检查几个复选框,然后点击

删除按钮。所有相应的记录都将被删除。


但是我遇到了困难...

现在每个复选框的NAME属性是

对应记录的主键。因此,如果我知道检查了哪些复选框,我只需使用NAME值使用DELETE。


一般来说,如何让服务器端看到检查了哪些复选框




复选框名称可能不是连续的,如果有任何记录被删除

之前,第一个复选框可能是一个大于0的数字。


有一个简单的机制来执行此操作吗?某种内置的cnotrol数组

允许我遍历提交的表单上的每个复选框?


我可以存储最后一个和第一个复选框隐藏输入中的数字,然后

循环开始/结束这些值,但这可能会循环很多

不存在的控件。

想法?


< Ade

-

Adrian Parker。被任命的牧师。 < ad *********** @ sympatico.ca>


将图形暴力视为娱乐的社会......不应该是
毫无意义的暴力事件打破了最年轻的梦想和b $ b bigh bigh...... - 少尉(2004年3月)

解决方案

我过去通过给每个复选框解决了这个问题

同名,比如id,但是然后将值语句设置为

主键我正在使用。当你查看_POST数组时,你应该找到

,每个被检查的id都在逗号分隔的列表中。只需处理

此列表,因为您需要循环选定的主键。


Adrian Parker写道:

我有一个PHP生成的页面显示X许多记录。每条记录都有一个复选框。用户检查几个复选框,然后点击
删除按钮。所有相应的记录都将被删除。

但我遇到了困难...

现在每个复选框的NAME属性是主键。
相应记录。因此,如果我知道检查了哪些复选框,我只需使用NAME值使用DELETE。

一般来说,如何让服务器端查看哪些复选框是
检查?

复选框名称可能不是顺序的,如果以前删除了任何记录,并且第一个复选框可能是大于0的数字。

有一个简单的机制来做到这一点?某种内置的cnotrol数组
允许我遍历提交的表单上的每个复选框?

我可以将最后一个和第一个复选框号存储在隐藏的输入中,然后
循环开始/结束这些值,但这可能会循环很多不存在的
控件。

想法?

< Ade



-

Martin

(个人电子邮件: ma **** @ galese.net

(工作/学术邮箱: ** @ uchicago.edu


一旦男人决定允许一切手段来对抗邪恶,

那么他们的好处就变成了与他们打算摧毁的邪恶无法区分。

- 克里斯托弗·道森


"以及这种灰色精神渴望渴望

跟随沉沦之星的知识,

超越人类思想的最大限度。

- Lord Alfred Tennyson


" Martin Andrew Galese" <毫安**** @ galese.net>在消息中写道

news:rn ************** @ news.uchicago.edu ...

我已经解决了过去这个问题是给每个复选框
同名,比如id,但是然后将值语句设置为
主键我在。当你查看_POST数组时,你会发现
每个被检查的id都在一个以逗号分隔的列表中。只需处理此列表,因为您需要循环选定的主键。


我不知道复选框可能有值。很酷。


之前我使用过POST数组的唯一方法是做一些事情:

if(isset(


_POST [" controlname"]))

如何使用您的方法引用它?

Adrian

我有一个PHP生成的页面,显示X许多记录。每条记录
前面都有一个复选框。用户检查几个复选框,然后点击
删除按钮。所有相应的记录都将被删除。

但我遇到了困难...

现在每个复选框的NAME属性是主键。
相应记录。因此,如果我知道检查了哪些复选框,我只需使用NAME值使用DELETE。

一般来说,如何让服务器端查看哪个检查
框是检查?

复选框名称可能不是顺序的,如果以前删除了任何记录
,并且第一个复选框可能是大于0的数字。

有一个简单的机制来做到这一点?某种内置的cnotrol
数组允许我遍历提交的表单上的每个复选框?

我可以将最后一个和第一个复选框号存储在隐藏的输入中,然后
循环开始/结束这些值,但这可能会循环很多不存在的
控件。

想法?

< Ade



-
Martin
(个人电子邮件: ma **** @ galese.net
(工作/学术电子邮件: an**@uchicago.edu
一旦人们决定允许一切手段与邪恶作斗争,那么他们的善行就会与他们打算摧毁的邪恶无法区分。
- 克里斯托弗·道森

这种渴望渴望的灰色精神
追随知识,像一个沉没的明星,
超越人类思想的最大限度。
- Lord Alfred Tennyson



I have a PHP generated page which displays X many records. Each record has
a checkbox preceding it. The user checks several checkboxes, and hits a
delete button. All the corresponding records will be deleted.

But I''m running into difficulty...
Right now the NAME property of each check box is the primary key of the
corresponding record. Hence if I know which checkboxes are checked, I
simply use DELETE using the NAME value.

Generally speaking, how do I get the server side to see which check boxes
were checked?

The check box names may not be sequential, if any records have been deleted
previously, and the first check box might be a number greater than 0.

Is there an easy mechanism to do this? Some kind of built in cnotrol array
allowing me to loop over every check box that was on the form submitted?

I could store the last and first checkbox number in a hidden input, then
loop starting/ending at those values, but that may loop over a lot of
controls that do not exist.
Thoughts?

<Ade
--
Adrian Parker. Ordained priest. <ad***********@sympatico.ca>

"A society that views graphic violence as entertainment ...should not be
surprised when senseless violence shatters the dreams of it''s youngest and
brightest..." - Ensign (March 2004)

解决方案

I''ve solved this problem in the past by giving each of the checkboxes
the same name, say id, but then setting the value statement to the
primary key I''m on. When you look in your _POST array, you should find
that each id that was checked is in a comma separated list. Just process
this list as you need to loop over the selected primary keys.

Adrian Parker wrote:

I have a PHP generated page which displays X many records. Each record has
a checkbox preceding it. The user checks several checkboxes, and hits a
delete button. All the corresponding records will be deleted.

But I''m running into difficulty...
Right now the NAME property of each check box is the primary key of the
corresponding record. Hence if I know which checkboxes are checked, I
simply use DELETE using the NAME value.

Generally speaking, how do I get the server side to see which check boxes
were checked?

The check box names may not be sequential, if any records have been deleted
previously, and the first check box might be a number greater than 0.

Is there an easy mechanism to do this? Some kind of built in cnotrol array
allowing me to loop over every check box that was on the form submitted?

I could store the last and first checkbox number in a hidden input, then
loop starting/ending at those values, but that may loop over a lot of
controls that do not exist.
Thoughts?

<Ade


--
Martin
(Personal email: ma****@galese.net)
(Work/Academic email: an**@uchicago.edu)

"As soon as men decide that all means are permitted to fight an evil,
then their good becomes indistinguishable from the evil that
they set out to destroy."
- Christopher Dawson

"And this gray spirit yearning in desire
To follow knowledge like a sinking star,
Beyond the utmost bound of human thought."
- Lord Alfred Tennyson


"Martin Andrew Galese" <ma****@galese.net> wrote in message
news:rn**************@news.uchicago.edu...

I''ve solved this problem in the past by giving each of the checkboxes
the same name, say id, but then setting the value statement to the
primary key I''m on. When you look in your _POST array, you should find
that each id that was checked is in a comma separated list. Just process
this list as you need to loop over the selected primary keys.
I didn''t know the checkbox could have a value. Cool.

The only way I''ve used the POST array before was by doing things like:
if (isset(


_POST["controlname"]))

How do you reference it using your method?
Adrian


Adrian Parker wrote:

I have a PHP generated page which displays X many records. Each record has a checkbox preceding it. The user checks several checkboxes, and hits a
delete button. All the corresponding records will be deleted.

But I''m running into difficulty...
Right now the NAME property of each check box is the primary key of the
corresponding record. Hence if I know which checkboxes are checked, I
simply use DELETE using the NAME value.

Generally speaking, how do I get the server side to see which check boxes were checked?

The check box names may not be sequential, if any records have been deleted previously, and the first check box might be a number greater than 0.

Is there an easy mechanism to do this? Some kind of built in cnotrol array allowing me to loop over every check box that was on the form submitted?

I could store the last and first checkbox number in a hidden input, then
loop starting/ending at those values, but that may loop over a lot of
controls that do not exist.
Thoughts?

<Ade


--
Martin
(Personal email: ma****@galese.net)
(Work/Academic email: an**@uchicago.edu)

"As soon as men decide that all means are permitted to fight an evil,
then their good becomes indistinguishable from the evil that
they set out to destroy."
- Christopher Dawson

"And this gray spirit yearning in desire
To follow knowledge like a sinking star,
Beyond the utmost bound of human thought."
- Lord Alfred Tennyson



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

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