Ticking a check box based on a value from a record

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Ian Davies

    Ticking a check box based on a value from a record

    Hello
    I am retreiving records into a table (part of the code below)

    <td width="20%" class="BodyText "><span class="style38" ><?php echo
    $commindex; ?></span></td>
    <td width="10%" class="BodyText "><span class="style38" ><?php echo
    $username; ?></span></td>
    <td width="45%" class="BodyText "><span class="style38" ><?php echo
    $comment; ?></span></td>
    <td width="10%" class="BodyText "><span class="greenbod y">
    <input name="checkbox2 " type="checkbox" value="<?php echo <td
    width="20%" class="BodyText "><span class="style38" ><?php echo $commindex;
    ?></span></td>
    <td width="10%" class="BodyText "><span class="style38" ><?php echo
    $username; ?></span></td>
    <td width="45%" class="BodyText "><span class="style38" ><?php echo
    $comment; ?></span></td>
    <td width="10%" class="BodyText "><span class="greenbod y">
    <input name="checkbox2 " type="checkbox" value="<?php echo
    $available; ?>" MYFUNCTIONHERE>
    </span></td>; ?>">
    </span></td>


    The last cell contains a check box, its value is set to $available. which is
    a value of 1 or 0.
    Trouble is I want the check box to be ticked if the value is 1 and unticked
    if the value is 0
    I thought of using a function such as

    function checked($avail) {
    if ($avail = $available) {
    return 'checked';
    }
    }

    after the value part of the code (where I have written MYFUNCTIONHERE)
    which would put the work 'checked' in the appropriate place
    but my inexperience means I cant get the syntax correct

    can anyone help

    Ian


  • Ian Davies

    #2
    Re: Ticking a check box based on a value from a record

    Ignore my question I just found it

    if($available == 1){echo " CHECKED";}

    Thanks for your time
    Ian

    "Ian Davies" <iandan.dav@vir gin.net> wrote in message
    news:JH2eg.2661 $zv2.1351@newsf e4-gui.ntli.net...[color=blue]
    > Hello
    > I am retreiving records into a table (part of the code below)
    >
    > <td width="20%" class="BodyText "><span class="style38" ><?php echo
    > $commindex; ?></span></td>
    > <td width="10%" class="BodyText "><span class="style38" ><?php echo
    > $username; ?></span></td>
    > <td width="45%" class="BodyText "><span class="style38" ><?php echo
    > $comment; ?></span></td>
    > <td width="10%" class="BodyText "><span class="greenbod y">
    > <input name="checkbox2 " type="checkbox" value="<?php echo <td
    > width="20%" class="BodyText "><span class="style38" ><?php echo $commindex;
    > ?></span></td>
    > <td width="10%" class="BodyText "><span class="style38" ><?php echo
    > $username; ?></span></td>
    > <td width="45%" class="BodyText "><span class="style38" ><?php echo
    > $comment; ?></span></td>
    > <td width="10%" class="BodyText "><span class="greenbod y">
    > <input name="checkbox2 " type="checkbox" value="<?php echo
    > $available; ?>" MYFUNCTIONHERE>
    > </span></td>; ?>">
    > </span></td>
    >
    >
    > The last cell contains a check box, its value is set to $available. which[/color]
    is[color=blue]
    > a value of 1 or 0.
    > Trouble is I want the check box to be ticked if the value is 1 and[/color]
    unticked[color=blue]
    > if the value is 0
    > I thought of using a function such as
    >
    > function checked($avail) {
    > if ($avail = $available) {
    > return 'checked';
    > }
    > }
    >
    > after the value part of the code (where I have written MYFUNCTIONHERE)
    > which would put the work 'checked' in the appropriate place
    > but my inexperience means I cant get the syntax correct
    >
    > can anyone help
    >
    > Ian
    >
    >[/color]


    Comment

    Working...