SitePoint Sponsor

User Tag List

Results 1 to 6 of 6

Hybrid View

  1. #1
    SitePoint Evangelist chiphunt1's Avatar
    Join Date
    Oct 2003
    Location
    louisville, ky
    Posts
    436
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    grey out checkbox

    i have an array of checkboxes that are displayed in a table. if the first checkbox is selected then all other checkboxes need to be greyed out, so that the user cannot select anything else. And of course if the first checkbox is unchecked then all checkboxes become available again. Any combination of the checkboxes may be selected unless the first one is selected. Thanks in advance.

  2. #2
    SitePoint Wizard silver trophy
    Join Date
    May 2003
    Posts
    1,843
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Please post your HTML.
    ::: certified wild guess :::

  3. #3
    SitePoint Evangelist chiphunt1's Avatar
    Join Date
    Oct 2003
    Location
    louisville, ky
    Posts
    436
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It's actually PHP - HTML, here is the code:
    $getOptions = @mysql_query("SELECT optID,opt_number,name FROM brute_options ORDER BY opt_number" );
    $num=mysql_numrows($getOptions);

    for ($x=0;x< $num;x++) {
    $optID=mysql_result($getOptions,$x,"optID");
    $opt_number=mysql_result($getOptions,$x,"opt_number");
    $name=mysql_result($getOptions,$x,"name"); ?>

    <tr>
    <td width="50" align="center"><input type="checkbox" name="options[]" value="<?=$opt_number?>" return doIt("<? echo ($x) ?>")></td>
    <td width="50" align="center" class="content"><?=$opt_number?></td>
    <td width="425" class="content"><?=$name?></td>
    </tr>
    <? } ?>

  4. #4
    SitePoint Evangelist chiphunt1's Avatar
    Join Date
    Oct 2003
    Location
    louisville, ky
    Posts
    436
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    of course the above code is inside a form
    <form action="<?=$PHP_SELF?>" method="post" name="step7" id="step7">
    <p>Please select any options you need/p>
    <table width="525" border="1" cellpadding="0" cellspacing="0" bordercolor="#DEDEDE">
    <tr bgcolor="#DEDEDE">
    <td width="50">&nbsp;</td>
    <td width="50" align="center">&nbsp;</td>
    <td width="525" class="content"><strong>description</strong></td>
    </tr>

    <-- code from above here -->

    <input name="submit" type="submit" id="submit" value="Submit">
    </form>

  5. #5
    SitePoint Wizard silver trophy
    Join Date
    May 2003
    Posts
    1,843
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    <lecture type="friendly"> Just fyi: this is a client-side operation, so your PHP makes it harder to deal with. Post generated (served) HTML/JS that can be modified. The easier you make it, the likelier you are to get a documented answer. </lecture>
    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" 
        "http://www.w3.org/TR/html4/loose.dtd">
    
    <html>
    <head>
    <title>untitled</title>
    <script type="text/javascript" language="javascript">
    
    function toggleGrp(oCheckbox)
    {
    	var bWhich = oCheckbox.checked;
    	var c = 1, box, grp = oCheckbox.form[oCheckbox.name];
    	while (box = grp[c++])
    	{
    		if (bWhich)
    			box.checked = false;
    		else box.checked = box.wasChecked || false;
    		box.disabled = bWhich;
    	}
    	return true;
    }
    
    </script>
    </head>
    <body>
    <form>
    <input type="checkbox" name="options[]" onclick="return toggleGrp(this)">____<strong>master</strong><br /><br />
    <input type="checkbox" name="options[]" onclick="this.wasChecked=this.checked">__box 1<br />
    <input type="checkbox" name="options[]" onclick="this.wasChecked=this.checked">__box 2<br />
    <input type="checkbox" name="options[]" onclick="this.wasChecked=this.checked">__box 3<br />
    <input type="checkbox" name="options[]" onclick="this.wasChecked=this.checked">__box 4<br />
    </form>
    </body>
    </html>
    Added a little touch: the previously checked boxes 'return' if the main box is unchecked. If you don't care for that, just remove the green lines.

    cheers, adios
    ::: certified wild guess :::

  6. #6
    SitePoint Evangelist chiphunt1's Avatar
    Join Date
    Oct 2003
    Location
    louisville, ky
    Posts
    436
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Adios,

    You are a star! Thanks alot... I am a computer programmer recently turned web developer. I know html and c/c++, so php comes easily to me. Javascript I am still struggling with. Your help is greatly appreciated. Take it easy..


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
  •