Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
Javascript How-To Ask your "How do I do this with Javascript?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old August 18th, 2005, 06:20 AM
Authorized User
 
Join Date: Jun 2003
Location: Bromsgrove, Worcestershire, United Kingdom.
Posts: 59
Thanks: 0
Thanked 0 Times in 0 Posts
Default Javascript with <div>

Hi All

I have a page (no form) with a series of check boxes, I have 2 functions to select / deselect all.

Here is one of the functions
function doSelectAll()
{
  var el = document.all;
    for (var i=0; i < el.length; i++)
    {
        if (el[i].type == 'checkbox')
        {
           el[i].checked = true;
        }
     }
}

All the checkboxes are in a table in a div, I also have other checkboxes on the page that I don't want to select.

How do I modify my script to only act on the div or table, and not the whole page. I know the problem is with my document.all but cant figure how to limit it.

Thanks

Andy G
  #2 (permalink)  
Old August 18th, 2005, 08:19 AM
Friend of Wrox
 
Join Date: Oct 2004
Location: delhi, delhi, India.
Posts: 553
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via MSN to vinod_yadav1919 Send a message via Yahoo to vinod_yadav1919
Default

Hii Aware!!

you can use el[i].name=="urchkboxgrpname"
 el[i].id=="urchkboxgrpname"
so that only checkboxes with particular group can be checked or unchecked

Hope this will help you


Cheers :)

vinod
  #3 (permalink)  
Old August 18th, 2005, 08:58 AM
Authorized User
 
Join Date: Jun 2003
Location: Bromsgrove, Worcestershire, United Kingdom.
Posts: 59
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi

Thanks for the reply.

I cannot use Name as the checkboxes are named - Check & ' Database driven ID'

How do you place a set of checkboxes in a group, I thought that was for radio buttons.

Andy
  #4 (permalink)  
Old August 25th, 2005, 05:57 AM
Friend of Wrox
 
Join Date: Oct 2004
Location: delhi, delhi, India.
Posts: 553
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via MSN to vinod_yadav1919 Send a message via Yahoo to vinod_yadav1919
Default

Hii Aware!!
Then you can compare the name of checkbox with indexOf("Check")

e.g
ur database driven checkboxes are
 Check123
 Check456

now
 varcheckbox=el[i].name
 if(varcheckbox.indexOf("Check")!=-1)
 {
//this checkbox is not related to Check123 ,Check 456
 }
else{
//this checkbox is related to Check123 ,Check 456
}

hope this will help you

Cheers :)

vinod


Similar Threads
Thread Thread Starter Forum Replies Last Post
hide the <div> crmpicco Javascript How-To 1 August 22nd, 2005 09:43 PM
<style> tags in a <body> vs. <div> bcat BOOK: Beginning CSS: Cascading Style Sheets for Web Design ISBN: 978-0-7645-7642-3 1 March 27th, 2005 08:50 AM
sizeable <div> johnjohn Javascript How-To 1 December 8th, 2004 08:28 PM
scrolling <DIV> anshul Javascript How-To 12 August 4th, 2004 09:51 AM
<A><DIV><TABLE></DIV></A> anshul HTML Code Clinic 2 July 17th, 2004 02:17 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.