SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Addict dr_dumb99's Avatar
    Join Date
    Sep 2004
    Location
    Pakistan
    Posts
    304
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Select All/Deselect All Problem

    Hi!

    I have created records through php coding loop.

    Alongwith database records , I have also dynamically created checkboxes for some actions like edit/delete etc. But when I click on "select All/DeSelect All" checkbox [it is statically created], javascript doesn't run and gives error.

    NOTE: I have two other input fields on the same page.


    Web page form name is 'scart' . My "Select All/DeSelect All" checkbox is as follows:
    /*******************************/
    <input type="checkbox" name="chk" value="1" onclick="javascript:chkbox('scart','chk');" />

    /*******************************/

    My javascript chkbox function is as follows
    /*******************************/
    function chkbox(frm,chk)
    {
    if(document.frm.chk.checked)
    {
    t=document.frm.length;
    for(i=0; i<t; i++)
    {
    document.frm[i].checked=true;
    }

    }
    else
    {
    t=document.frm.length;
    for(i=0; i<t; i++)
    {
    document.frm[i].checked=false;
    }
    }
    }
    /*******************************/


    Kindly give me some solution.

    Thanks in advance

  2. #2
    SitePoint Wizard
    Join Date
    Nov 2004
    Location
    Nelson BC
    Posts
    2,310
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    use
    Code:
    <input type="checkbox" name="chk" value="1" onclick="chkbox(this);" />
    with
    Code:
    function chkbox(theCheckbox) {
    	var theForm = theCheckbox.form;
    	for( var i=0; i < theForm.elements.length; i++ ) {
    		if( theForm.elements[i].type.toLowerCase() == "checkbox" ) {
    			theForm.elements[i].checked = theCheckbox.checked;
    		}
    	}
    }


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •