SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Addict mcrumlish's Avatar
    Join Date
    Jan 2002
    Posts
    384
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    preventing users ticking a checkbox until a <select> option is selected

    Hi,

    I am having some problems with some javascript for an application I have.

    Firstly, I have a form that has a <select> menu with 5 options and below that I have 3 checkboxes. What I want to do is, prevent the user from ticking one of the checkboxes unless they have selected the 5th element in the dropdown menu first.

    In other sites I have seen something similar where form elements are shaded out and aren't selectable until the user performs some action.

    Ideally I want to do this using javascript and without having to reload the page.

    Any help with this is appreciated a lot!

    Thanks,
    Martin

  2. #2
    SitePoint Enthusiast mutus's Avatar
    Join Date
    Sep 2003
    Location
    NY, USA
    Posts
    72
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    play around with this:
    Code:
    <script type="text/javascript">
    <!--
    function ckBoxes(sl, f){
    	var state = (sl.selectedIndex!=4);
    	f.ck1.disabled = state;	
    	f.ck2.disabled = state;
    	f.ck3.disabled = state;
    }
    //-->
    </script>
    
    <form action="" name="frm">
      <select name="sel" onchange="ckBoxes(this,this.form)">
        <option value="option1">option 1</option>
        <option value="option2">option 2</option>
        <option value="option3">option 3</option>
        <option value="option4">option 4</option>
        <option value="option5">option 5</option>
      </select>
      <br />
      <input type="checkbox" name="ck1" value="ck1" disabled="disabled" />
      <input type="checkbox" name="ck2" value="ck2" disabled="disabled" />
      <input type="checkbox" name="ck3" value="ck3" disabled="disabled" />
    </form>
    That's just one way to go about it. good luck

  3. #3
    SitePoint Zealot jadmadi's Avatar
    Join Date
    Sep 2003
    Location
    Jordan
    Posts
    154
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Good idea, Good luck

  4. #4
    SitePoint Addict mcrumlish's Avatar
    Join Date
    Jan 2002
    Posts
    384
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks, that code works but I will need some help to integrate it with my code.

    My checkboxes are created dynamically and they are named so that the values can be used by PHP as an array.

    I name the checkboxes like this:

    Code:
    <input type="checkbox" name="adminusers[]" value="<?=$adminrow[userid];?>">
    How would I integrate that with your script seeing as each checkbox element has the same name for the purposes of creating an array?

    Thanks,
    Martin


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
  •