Page 1 of 2 12 LastLast
Results 1 to 10 of 12

Thread: Disable checkboxes based in other checkboxes.

  1. #1
    Join Date
    Apr 2006
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Disable checkboxes based in other checkboxes.

    Hello,
    i'm new here
    I need some help, i have a hosting directory and in the submission page the categories are selected using checkboexes.
    A site can be submitted to many directories, but some users are abusing and submitting their sites for example to the windows hosting and to the linux hosting directories at the same time, which is ridiculous.

    So i need to disable the checkbox of the windows category when the linux checkbox is checked and viceversa.
    Same goes for the resellers, shared and dedicated categories, when one is selected the other should be disabled.

    Can someone help me?

    Thanks so much in advance.
    Gaston

  2. #2
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Pointless. Check it server-side.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  3. #3
    Join Date
    Apr 2006
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Well, i'm trying too but having both solutions will help me decide which to use.
    Why you say it's pointless?

  4. #4
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    The downside to that, though, is you'd have to decide.

    If one clicked "windows", then "linux", it would switch to linux, meaning that's their first choice.

    If it were server side, you'd have to say "if both, then choose windows" while linux might be their first choice.

    then again, they're abusing the site, as you said, so not like you care that much about what they want ^_^

    Server side is more secure, and probly easier, though.

  5. #5
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    You cannot use Javascript alone for this. It can be bypassed with ease.
    You have two options: to use server-side checking, or to use both server-side and client-side.
    Besides, what if they do indeed offer both Windows and Linux hosting?
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  6. #6
    Join Date
    Apr 2006
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    If one clicked "windows", then "linux", it would switch to linux, meaning that's their first choice.
    i get your point, but what i need is to dissable the windows checkbox if the linux is selected, by dissable i mean it's not clickeable, it'll become clickeable only if the user unselects "linux"
    then again, they're abusing the site, as you said, so not like you care that much about what they want ^_^
    I care about what honest users want, a fair directory.
    I don't care about what not honest users want which is to promote their websites spamming.

    Twey,
    thanks for your reply
    Besides, what if they do indeed offer both Windows and Linux hosting?
    I'm trying to disable this in a page to add hosting plans, registered hosting companies can add as many plans as they want, if the company offers hosting and linux plans they can add both of them.

  7. #7
    Join Date
    Dec 2005
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    maybe i'm just missing something... but if you only want one or the other checked... why not just use radio buttons?

  8. #8
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Aha, very well. This makes sense.
    Ickyb0d: If there are more than one set of buttons, this could be problematical.
    Code:
    <script type="text/javascript">
    function checkDepends(element) {
      for(var i=0;i<element.form.elements.length;i++)
        if(element.form.elements[i].className.indexOf("depends-" + element.name) != -1)
          element.form.elements[i].disabled = element.checked;
        else if(element.form.elements[i].className.indexOf("conflicts-" + element.name) != -1)
          element.form.elements[i].disabled = !element.checked;
    }
    </script>
    
    <!-- This should allow you to create a form like this: -->
    
    <form action="f.php" method="post">
      <input type="checkbox" name="linux" class="conflicts-windows">
      <input type="checkbox" name="ssh" class="depends-linux">
      <input type="checkbox" name="cpanel" class="depends-linux">
      <input type="checkbox" onclick="checkDepends(this);" name="windows" class="conflicts-linux">
      <input type="checkbox" name="aspdotnet" class="depends-windows">
      <input type="text" name="netbiosname" class="depends-windows">
    </form>
    Untested, but should work. Remember that it isn't a secure solution, and must be used in tandem with a server-side check.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  9. #9
    Join Date
    Apr 2006
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Thanks so much!, i'm going to try this right now

  10. #10
    Join Date
    Apr 2006
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Well, it's not working very well, however i'll try to make it server side as you suggested.
    Thanks so much again!

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
  •