Re: QuickForm multiple checkboxes and Javascript
| From: | Matte Edens | Date: | Fri, 15 Apr 2005 19:05:50 +0000 |
| Subject: | Re: QuickForm multiple checkboxes and Javascript | ||
| References: | 1 2 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-18769@lists.php.net to get a copy of this message | ||
Instead of putting $tmp->id in the name of the checkbox, I prefer to put it in the value of the checkbox. Since you're setting value="1", it's assumed that you want that particular item you are checking off. Just set the name to line[], set the value to $tmp->id and then explode() the element values in php when evaluating what was POSTed.
BTW - here's my JS for selecting all items. It's designed for checkboxes where the id is NOT in the name of the element.
// toggleSelectAll
// @param elt the checkbox element that is the "select all" choice in the form
// @param chkColName the name of the checkbox collection to get
function toggleSelectAll(elt, chkColName) {
var checks = document.getElementsByName(chkColName);
for (var i = 0; i < checks.length; i++) {
checks[i].checked = elt.checked;} } matte - matte@arubanetworks.com webmonkey » arubanetworks.com <http://www.arubanetworks.com> Get Firefox! <http://www.spreadfirefox.com/community/?q=affiliates&id=2885&t=85> | Reclaim Your Inbox! <http://www.mozilla.org/products/thunderbird> Justin Patrin wrote:
On 4/15/05, Webmaster <webmaster@lindworm.de> wrote:Hi, I have the following problem. I select x rows from my database and dispaly them in table rows. Each Tablerow should have a checkbox field wich can be checked and sended to delete the database entry. Therefore I generate the checkboxes the following way. foreach($rows as $tmp) { $form->addElement('checkbox','line['.$tmp->id.']','Barrierefrei','','','0'); } Now I get checkboxes looking like that. <input type="checkbox" name="line[12]" id="line[12]" value="1"> <input type="checkbox" name="line[45]" id="line[45]" value="1"> Now to my problem. Is there a way to select or deselect all Checkboxes with a Javascript ?You can probably use getElementByType (I think this is right) to get all checkboxes, but a better solution (IMHO) is to set up a JS array which has the ids of all of your checkboxes.