How do you do selected in a multi-value list box in a form?

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

    #1

    How do you do selected in a multi-value list box in a form?

    I am populating a list box from a dictionary table and then picking
    muliple values to insert into a detail table. How do I get the list box
    to have multiple selections highlighted when I pick one of the master
    items?

  • rich

    #2
    Re: How do you do selected in a multi-value list box in a form?

    Here is part of the code with explaination

    This is the cell in a table that is part of a form.

    <td>
    <select name="stages[]" multiple="multi ple">
    <?php
    $allstages = allstages();
    while ($allstagerows= pg_fetch_array( $allstages)) {
    $eachstage= $allstagerows["stageid"];
    while($drcatrow = pg_fetch_array( $dresscat)){
    if ($drcatrow["stageid"] == $eachstage){ ?>
    <option value=<?php echo $eachstage;?> selected="selec ted"><?php
    echo $allstagerows["stage"]?></option>
    <?php }else{ ?>
    <option value=<?php echo $eachstage;?>>< ?php echo
    $allstagerows["stage"]?></option>
    <?php }
    }
    }
    ?>
    </select>
    </td>

    Comment

    • rich

      #3
      Re: How do you do selected in a multi-value list box in a form?

      Here is the form I designed.
      This form is to take a dressing type and choose all the wound stages it
      can be used on.
      there are 3 tables

      dressing type table
      dresstypeid
      dressingtype

      stages table
      stageid
      stage

      dressingcat table
      dresstypeid
      stageid

      <form name="dresstype form" method="post" action="<?php print
      $_SERVER['PHP_SELF']?>">
      <?php
      $dresstypeid = $_REQUEST['dresstypeid'];
      if ($dresstypeid >0) {
      $drtresult = specificdressty pe($dresstypeid ); // query for the
      specific dressing type
      $dresscat = specdresscat($d resstypeid); //query for the wound stages
      for a dressing type
      $drtyperow = pg_fetch_array( $drtresult);
      ?>
      <input type=hidden name="dresstype id" value= "<?php echo
      $drtyperow["dresstypei d"]?>">
      <?php
      }
      ?>
      <input type=hidden name="dresstype id" value= "<?php echo
      $drtyperow["dresstypei d"]?>">
      <fieldset>
      <legend>Dressin g Type Information</legend>
      <table align="left">
      <tr>
      <td><label for "dresstype">Dre ssing type</label></td>
      </tr>
      <tr>
      <td><input type=text size="50" name=dresstype value = "<?php echo
      $drtyperow["dressingty pe"]?>" ></td>
      </tr>
      <tr>
      <td><label for "stages">Stages </label></td>
      </tr>
      <tr>
      <td>
      <select name="stages[]" multiple="multi ple">
      <?php
      $allstages = allstages(); //query to populate the listbox with all the
      stages in the stage table
      while ($allstagerows= pg_fetch_array( $allstages)) {
      $eachstage= $allstagerows["stageid"];
      while($drcatrow = pg_fetch_array( $dresscat)){
      if ($drcatrow["stageid"] == $eachstage){ ?>
      <option value=<?php echo $eachstage;?> selected="selec ted"><?php echo
      $allstagerows["stage"]?></option>
      <?php }else{ ?>
      <option value=<?php echo $eachstage;?>>< ?php echo
      $allstagerows["stage"]?></option>
      <?php }
      }
      }
      ?>
      </select>
      </td>
      </tr>
      </table>
      </fieldset>
      <table align="left">
      <tr>
      <td><input type="submit" name="upddresst ype" value="Add-Update Dressing
      Type" ></td>
      </tr>
      </table>

      </form>

      Comment

      Working...