Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New to the CF scene
    Join Date
    Oct 2008
    Posts
    9
    Thanks
    4
    Thanked 0 Times in 0 Posts

    checkbox conditions

    Hey Everyone,

    I am trying to code a form with checkboxes that list out scheduled sessions during a conference. There are 2 different types of sessions all on the same day. There is full day sessions and half day sessions, either starting at 9:30 or at 1:30. I want to make it that if you choose one of the 3 full day sessions, then you can't choose anything else, the other checkboxes are disabled. If you choose one of the 5 half day sessions, then the full day sessions are disabled. Here is the kicker though, with the half day sessions, they 3 are at 9:30 and 2 are at 1:30. I want it that if you choose a 9:30 half day session, then all of the other 9:30 sessions are disabled which would leave only the 1:30 session enabled and vice versa. Of course, when you uncheck one of the boxes, then it resets the boxes and makes the other checkboxes enabled if they were disabled before. Does that make sense? Any help is greatly appreciated!

  • #2
    Banned
    Join Date
    May 2006
    Location
    England
    Posts
    664
    Thanks
    0
    Thanked 84 Times in 84 Posts
    This solution uses a master-slave checkbox controller to achieve what (I think) you specified. The only slight imperfection is that because there's no conditional logic, some checkboxes could become enabled at the wrong time, but checking one would still cancel out anything ineligible: Demo.

  • Users who have thanked Arty Effem for this post:

    saxy46 (10-14-2008)

  • #3
    New to the CF scene
    Join Date
    Oct 2008
    Posts
    9
    Thanks
    4
    Thanked 0 Times in 0 Posts
    Hey Arty,

    Thanks so much for your response....Looks a lot cleaner then my code! I was doing a lot of if else statements....I will play around with it and see how it goes...Thanks again.

  • #4
    Senior Coder jmrker's Avatar
    Join Date
    Aug 2006
    Location
    FL
    Posts
    3,091
    Thanks
    38
    Thanked 498 Times in 492 Posts

    Lightbulb Alternate solution ...

    I read the original requirements differently. I thought you wanted the conditions checked for each of three days. Here's what I came up with.
    PHP Code:
    <html>
    <
    head>
    <
    title>Schedule Problem</title>
    <
    script type="text/javascript">
    function 
    ScedAD(choice) {
      var 
    IDS;
      var 
    apd choice.split('-');
      if (
    document.getElementById(choice).checked == true) {
        for (
    i=1i<=3i++) { IDS='M-'+apd[1]+'-S'+i;
         
    document.getElementById(IDS).checked falsedocument.getElementById(IDS).disabled true; }
        for (
    i=1i<=2i++) { IDS='P-'+apd[1]+'-S'+i;
          
    document.getElementById(IDS).checked falsedocument.getElementById(IDS).disabled true; }
      } else {
        for (
    i=1i<=3i++) { IDS='M-'+apd[1]+'-S'+i;  document.getElementById(IDS).disabled false;  }
        for (
    i=1i<=2i++) { IDS='P-'+apd[1]+'-S'+i;  document.getElementById(IDS).disabled false; }
      }
      
    document.getElementById(choice).disabled false;
    }
    function 
    ScedPD(choice) {
      var 
    apd choice.split('-');
      var 
    flag document.getElementById(choice).checked;
      if (
    apd[0] == 'M') { 
        for (
    i=1i<=3i++) {
         
    IDS='M-'+apd[1]+'-S'+i;
         if (
    flag == true) { document.getElementById(IDS).disabled true; }
                      else { 
    document.getElementById(IDS).disabled false; }
        }
      }
      if (
    apd[0] == 'P') { 
        for (
    i=1i<=2i++) {
         
    IDS='P-'+apd[1]+'-S'+i;
         if (
    flag == true) { document.getElementById(IDS).disabled true; }
                      else { 
    document.getElementById(IDS).disabled false; }
        }
      }
      
    document.getElementById(choice).disabled false;
    }
    function 
    ShowSelections() {
      var 
    IDarray = ['D-1-1','D-2-1','D-3-1'];
      var 
    str 'Decode settings';
    // alternatively, set values and use them to display current selections instead of decoding IDs
      
    for (i=0i<IDarray.lengthi++) {
        
    str += '\n\nDay '+(i+1)+'\n';
        if (
    document.getElementById(IDarray[i]).checked) { str += IDarray[i]+'\n'; }
        else {
          for (
    j=1j<=3j++) { IDS 'M-'+(i+1)+'-S'+j; if (document.getElementById(IDS).checked) { str += IDS '\n'; } }
          for (
    j=1j<=2j++) { IDS 'P-'+(i+1)+'-S'+j; if (document.getElementById(IDS).checked) { str += IDS '\n'; } }
        }
      }
      
    alert(str);
    }
    </script>
    </head>
    <body>
    <table border="1">
    <tr>
     <td>Day 1 Session<br>
      <input type="checkbox" id="D-1-1" onclick="ScedAD(this.id)" value=""> All-Day
     </td>
     <td>
      Half-Day Sessions<br>
      <input type="checkbox" id="M-1-S1" onclick="ScedPD(this.id)" value="">9:30 Session 1</br>
      <input type="checkbox" id="M-1-S2" onclick="ScedPD(this.id)" value="">9:30 Session 2</br>
      <input type="checkbox" id="M-1-S3" onclick="ScedPD(this.id)" value="">9:30 Session 3</br>
      <br>
      <input type="checkbox" id="P-1-S1" onclick="ScedPD(this.id)" value="">1:30 Session 1</br>
      <input type="checkbox" id="P-1-S2" onclick="ScedPD(this.id)" value="">1:30 Session 2</br>
     </td>
    </tr>
    <tr>
     <td>Day 2 Session<br>
      <input type="checkbox" id="D-2-1" onclick="ScedAD(this.id)" value=""> All-Day
     </td>
     <td>
      Half-Day Sessions<br>
      <input type="checkbox" id="M-2-S1" onclick="ScedPD(this.id)" value="">9:30 Session 1</br>
      <input type="checkbox" id="M-2-S2" onclick="ScedPD(this.id)" value="">9:30 Session 2</br>
      <input type="checkbox" id="M-2-S3" onclick="ScedPD(this.id)" value="">9:30 Session 3</br>
      <br>
      <input type="checkbox" id="P-2-S1" onclick="ScedPD(this.id)">1:30 Session 1</br>
      <input type="checkbox" id="P-2-S2" onclick="ScedPD(this.id)">1:30 Session 2</br>
     </td>
    </tr>
    <tr>
     <td>Day 3 Session<br>
      <input type="checkbox" id="D-3-1" onclick="ScedAD(this.id)" value=""> All-Day
     </td>
     <td>
      Half-Day Sessions<br>
      <input type="checkbox" id="M-3-S1" onclick="ScedPD(this.id)" value="">9:30 Session 1</br>
      <input type="checkbox" id="M-3-S2" onclick="ScedPD(this.id)" value="">9:30 Session 2</br>
      <input type="checkbox" id="M-3-S3" onclick="ScedPD(this.id)" value="">9:30 Session 3</br>
      <br>
      <input type="checkbox" id="P-3-S1" onclick="ScedPD(this.id)" value="">1:30 Session 1</br>
      <input type="checkbox" id="P-3-S2" onclick="ScedPD(this.id)" value="">1:30 Session 2</br>
     </td>
    </tr>
    </table>
    <input type="button" value="Current Selections" onClick="ShowSelections()">
    </body>
    </html> 
    The 'Current Selections' button is just to show the picks of the user. Could be used to display the 'values' of the selections instead.

    If of no use to you, then ignore the post.

  • Users who have thanked jmrker for this post:

    saxy46 (10-14-2008)

  • #5
    New to the CF scene
    Join Date
    Oct 2008
    Posts
    9
    Thanks
    4
    Thanked 0 Times in 0 Posts
    hey JM,

    thanks for the reply...I will take a look at your code as well!


  •  

    Tags for this Thread

    Posting Permissions

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