SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Addict
    Join Date
    Oct 2002
    Posts
    229
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Form disable.enable doesn't happen straight away

    Hello,

    I am creating a series of rows each have a number of checkboxes in.
    The checkbox in the first colom of the row determines wether the rest of that row's checkboxs are disabled or not.
    If the first checkbox is ticked then the rest of that row has enabled boxes.
    If the first checkbox is not ticked then the rest of that row isdisabled.

    I have written some code but it doesn't seem to action straight away. It is only once I tick somewhere else on the form that it takes place. Is this a Bug? I really want the rest of the row to be disabled/enabled immideatlely when the first column is checked/unchecked.
    Anty ideas?

    Code:
     
    HTML Code:
     <script> 
    function disable(){
    if(document.manager.members.checked==true) {
     document.manager.add_members.disabled=false;
     document.manager.delete_members.disabled=false;
     document.manager.approve_applicants.disabled=false;
    }
    else {
     document.manager.add_members.disabled=true;
     document.manager.add_members.checked=false;
     document.manager.delete_members.disabled=true;
     document.manager.delete_members.checked=false;
     document.manager.approve_applicants.disabled=true;
     document.manager.approve_applicants.checked=true;
    }
    }
    </script>
    <form action="site-managers.php" method=post name=manager>
    		  <table border="0" cellpadding="4" cellspacing="0" align=left>
    			<tr>
    			  <td><span class="style1">
    				<input type="checkbox" name="members" value="checkbox" onChange="javascript:disable();">
    				Members</span></td>
    			  <td><span class="style1">
    				<input type="checkbox" name="add_members" value="checkbox" onChange="javascript:disable();">
    				Add Members </span></td>
    			  <td><span class="style1">
    				<input type="checkbox" name="delete_members" value="checkbox" onChange="javascript:disable();">
    				Delete Members </span></td>
    			  <td><span class="style1">
    				<input type="checkbox" name="approve_applicants" value="checkbox" onChange="javascript:disable();">
    				Approve Applicants </span></td>
    
    			</tr>
      
    		
    		  </table>
    Eternity

  2. #2
    SitePoint Addict xDev's Avatar
    Join Date
    Jul 2003
    Location
    Moncton, New Brunswick, Canada
    Posts
    247
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    That's because your using the onchange event. Use the onclick:
    onclick="disable()"

    You don't need the javascript protocol in there either. an event drops into javascript automatically. If you were calling javascript from an href then you would use the javascript: protocol.

    -xDev

  3. #3
    SitePoint Wizard silver trophy rushiku's Avatar
    Join Date
    Dec 2003
    Location
    A van down by the river
    Posts
    2,056
    Mentioned
    0 Post(s)
    Tagged
    1 Thread(s)
    also, you want the first box to enable the rest in that row, so the others need to have disabled='true' in their defs. then firstBox.onclick.disable() will enable them the first time you click it

  4. #4
    SitePoint Addict
    Join Date
    Oct 2002
    Posts
    229
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanx - its always so simple isn't it!
    Eternity


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
  •