[Javascript] Select all when a chekcbox is checked

Reuben D Budiardja reubendb at goshen.edu
Sat Apr 28 15:45:54 CDT 2001


Another question:
Is there any way to address a selection box other by its name? The problme 
is, I'm also using php, and for php the name for <SELECT MULTIPLE> has to 
be something like "name[]" (implying it's an array from select multiple.

While addresing this name in the javascript function, the square bracket 
causes an error.
Any help? What is the general rule to address an object other by its name?

Thanks a lot.
Reuben D. Budiardja





At 03:15 PM 4/28/01 -0500, you wrote:
>This is great. Thanks a lot Peter.
>
>Reuben D. Budiardja
>
>
>At 03:00 PM 4/28/01 -0500, you wrote:
>>Reuben,
>>
>>         You would need an onClick() event handler in the checkbox that 
>> calls a
>>JavaScript function, like this:
>>
>><INPUT TYPE = "CHECKBOX" NAME="all"  onClick="selectAll()">
>>
>>         Then in the function you would iterate through the values in the 
>> SELECT
>>element and change the selected property to true, like this:
>>
>>function selectAll() {
>>
>>         var i = 0;
>>
>>         while(i<document.formName.selectName.options.length) {
>>                 document.formName.selectName.options[i].selected = true;
>>                 i+=1;
>>                 }
>>         }
>>
>>         I haven't tested this; it may be that you need to stop at 
>> length-1, but you
>>can tweak it as necessary.
>>
>>Cheers,
>>
>>Peter
>>
>>
>>|-----Original Message-----
>>|From: javascript-admin at LaTech.edu [mailto:javascript-admin at LaTech.edu]On
>>|Behalf Of Reuben D Budiardja
>>|Sent: Saturday, April 28, 2001 2:34 PM
>>|To: javascript at LaTech.edu
>>|Subject: [Javascript] Select all when a chekcbox is checked
>>|
>>|
>>|
>>|Hello,
>>|Suppose I have a multiple selection form, something like this:
>>|
>>|<SELECT NAME="assignments" MULTIPLE SIZE="9">
>>|   <OPTION NAME=bla>Bla
>>|   <OPTION NAME=foo>foo
>>|etc..
>>|</SELECT>
>>|
>>|<INPUT TYPE = "CHECKBOX" NAME="all> Select All
>>|
>>|What  I want to do is when the checkbox is checked, all the selection is
>>|selected. Could someone help me with this?
>>|
>>|Thanks A lot.
>>|Reuben D. Budiardja
>>|
>>|
>>|
>>|
>>|Reuben D. Budiardja
>>|Web Database Application Programmer / Analyst
>>|Devcorps, ITS
>>|Goshen College, IN 46526
>>|
>>|
>>|_______________________________________________
>>|Javascript mailing list
>>|Javascript at LaTech.edu
>>|http://www.LaTech.edu/mailman/listinfo/javascript
>>|
>>
>>
>>_______________________________________________
>>Javascript mailing list
>>Javascript at LaTech.edu
>>http://www.LaTech.edu/mailman/listinfo/javascript
>
>-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
>"God is the unrestricted act of understanding, the eternal rapture
>glimpsed in every Archimedean cry of Eureka."
>
>                         - Bernard Lonergan -
>~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^
>
>Reuben Donald Budiardja
>reubendb at goshen.edu
>Homepage: http://www.goshen.edu/~reubendb
>
>
>_______________________________________________
>Javascript mailing list
>Javascript at LaTech.edu
>http://www.LaTech.edu/mailman/listinfo/javascript





More information about the Javascript mailing list