My Custom Rack I Built
Reply to topic
 
use array to name checkbox

Junior Journeyman (L4)

Junior Journeyman (L4)

Joined:30 Jun 2004
Posts:105
Reply with quote
In my previous post, I asked how to check all rows' checkbox in a table if the first row's checkbox is checked, and I got the correct code for doing that. In the following code, book_click_all is the first row's checkbox name and check_book is the rest rows' checkbox name.

Now due to my application's other restriction, I have to change all names from check_book to check_book[]. Then the code below no longer works.
Is it possible to change the code somewhere in order to make it work if I have to have the name changed?

Thanks a lot.

Code:

function checkAll()
   {
      if(document.all.book_click_all.checked)
         for(var i=0;i<document.book.check_book.length;i++)
            document.book.check_book[i].checked=true;
      else
         for(var i=0;i<document.book.check_book.length;i++)
            document.book.check_book[i].checked=false;

   }
View user's profileFind all posts by scorpioySend private message
use array to name checkbox

Site Admin

Site Admin

Joined:30 Apr 2000
Posts:2841
Location:Texas, USA
Reply with quote
if you pass the name of the form checkbox variable:
function checkAll(_item)

then you can change the hardcoded references to check_book as follows using the eval function

WAS
document.book.check_book[i].checked=true;

IS
eval("document.book."+_item+"[i].checked=true;");

_________________
Cheers.

-- Mike Robb

joker
View user's profileFind all posts by mikeSend private messageVisit poster's website
use array to name checkbox
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum
All times are GMT - 6 Hours  
Page 1 of 1  


  
  
 Reply to topic