9 Javascripts You Better Not Miss!
By Kiran Pai2005-06-11
Example 1 : A Single click for checking-unchecking multiple check boxes
You must have seen this script working at many places. One that comes to my mind is at Yahoo / Hotmail for checking or unchecking all the mails that are visible on the page. There are lots of places where you can use this script, generally when you want the user to carry out some task on either all or none of the items that you present to him.
| <SCRIPT LANGUAGE = "JavaScript"> <!-- | |||
| function modify_boxes(to_be_checked,total_boxes){ | |||
| for ( i=0 ; i < total_boxes ; i++ ){ | |||
| if (to_be_checked){ | |||
| document.forms[0].chkboxarray[i].checked=true; | |||
| } | |||
| else{ | |||
| document.forms[0].chkboxarray[i].checked=false; | |||
| } | |||
| } | |||
| } | |||
| --> </SCRIPT> | |||
| <BODY> <FORM> <INPUT TYPE=checkbox NAME="chkboxarray" VALUE="1"><br> <INPUT TYPE=checkbox NAME="chkboxarray" VALUE="2"><br> <INPUT TYPE=checkbox NAME="chkboxarray" VALUE="3"><br> <INPUT TYPE=button NAME="CheckAll" VALUE="Check All Boxes" onClick="modify_boxes(true,3)"> <INPUT TYPE=button NAME="UnCheckAll" VALUE="UnCheck All Boxes" onClick="modify_boxes(false,3)"> </FORM> </BODY> | |||
Note : The VALUE tag for the checkboxes seem to have no use. But it is required to differentiate between the check boxes when you submit such a form to a server side program. You could differentiate between the checked boxed by giving different VALUEs to the checkbox.
Tutorial Pages:
» 9 Javascripts you better not miss!
» Example 1 : A Single click for checking-unchecking multiple check boxes
» Example 2 : Opening a page (existing as well as dynamic) in a new window without bars, buttons, etc.
» Example 3 : Multiple submit buttons on a single form (Submitting same form to any one of many programs)
» Example 4 : Emulating Browsers Back-Forward buttons
» Example 5 : Making the Output of a program (servlet/cgi program) to appear in a new frame
» Example 6 : Displaying a Countdown using Javascript
» Example 7 : Changing images with MouseOver and MouseOut events
» Example 8 : Checking the form contents before submitting the form
» Example 9 : Filling the values of a dropdown SelectMenu depending on the selection in another Menu
