[nycphp-talk] Javascript "select all" feature?
felix zaslavskiy
felix at bebinary.com
Tue Apr 13 15:53:09 EDT 2004
Try this:
for (var i = 0; i < document.imageForm.elements.length; i++){
if(document.imageForm.elements[i].type == 'checkbox'){
document.imageForm.elements[i].checked = true;
}
}
> I am producing a form using PHP on the back end and Javascript on the
> front end. The resulting script will come to the browser as follows:
>
> [Code]
> <script>
> <!--
> function selectAll() {
> moveElement = eval("document.imageForm.move" + "[]");
> alert(moveElement);
> if (document.imageForm.select_all[0].checked) {
> for (i = 0; i < document.imageForm.move.length; i++) {
> document.imageForm.move[i].checked = true;
> }
> }
> }
>
> function deSelectAll() {
> if (!document.imageForm.select_all[0].checked ||
> document.imageForm.deselect_all[0].checked) {
> for (i = 0; i < document.imageForm.move.length; i++) {
> document.imageForm.move[i].checked = false;
> }
> }
> }
> //-->
> </script>
> [/Code]
>
> This will work with a checkbox group that has to have this naming
> convention for PHP:
>
> [Code]
> <input type=checkbox name=move[] value="myImage.gif"> - Move?
> [/Code]
>
> I will also have a checkbox that will "select all" and "de-select all":
>
> [Code]
> <input type=checkbox name=select_all value=1 onChange="selectAll()"> -
> Select All
> <input type=checkbox name=deselect_all value=1 onChange="deSelectAll()">
> - De-select All
> [/Code]
>
> I am not familiar at how Javascript can work with non-standard naming
> conventions for event actions, can someone tell me what I'm doing
> wrong? This fails at least in Mozilla 1.6
>
> Thanx
> Phil
>
> _______________________________________________
> talk mailing list
> talk at lists.nyphp.org
> http://lists.nyphp.org/mailman/listinfo/talk
>
--
Felix Zaslavskiy
http://www.zaslavskiy.net
More information about the talk
mailing list