Skip to main content
Participant
December 12, 2011
Answered

Setting the Default Value for a dynamic select menu

  • December 12, 2011
  • 1 reply
  • 683 views

Hi I have a php page with 2 forms on it, one feeds the other to achieve a drill down (manufacturer > model). In the second select menu I have a default static value "Select Aircraft Model", I want to set a value for the first dynamic select menu to read "Select Aircraft Manufacturer". When I add a static value to my list it tells me I alreay have a dynamic behavior on this menu and to choose a different one. I have included the code for both menus. Thank you in advance, I know this must be a stupid question, but it's got me stumped.

Tom

//This is the menu I want to add the default static value to//

<td width="667"><select name="airMake" style="width: 200px;"onchange="this.form.submit();" id="airMake">

        <?php

do {

?>

        <option value="<?php echo $row_rsAirManufacturer['aircraft_manufacturer']?>"<?php if (!(strcmp($row_rsAirManufacturer['aircraft_manufacturer'], ((isset($_POST["airMake"]))?$_POST["airMake"]:"")))) {echo "selected=\"selected\"";} ?>><?php echo $row_rsAirManufacturer['aircraft_manufacturer']?></option>

        <?php

} while ($row_rsAirManufacturer = mysql_fetch_assoc($rsAirManufacturer));

  $rows = mysql_num_rows($rsAirManufacturer);

  if($rows > 0) {

      mysql_data_seek($rsAirManufacturer, 0);

      $row_rsAirManufacturer = mysql_fetch_assoc($rsAirManufacturer);

  }

?>

      </select>

      </td>

  </tr>

</table></form>

 

    <form action="quoteResult.php" method="post" name="quoteForm">

      <table width="100%" border="0" cellpadding="5px">

        <tr>

          <td width="260"style="color: #000; text-align: right;">Aircraft Model:</td>

          <td colspan="2"><span id="spryselect2">

//This is the menu that works correctly//

            <select name="airModel" style="width: 200px;" id="airModel">

              <option value="" <?php if (!(strcmp("", ((isset($_POST["airMakeField"]))?$_POST["airMakeField"]:"")))) {echo "selected=\"selected\"";} ?>></option>

              <?php

do { 

?>

              <option value="<?php echo $row_rsAirModel['aircraft_model']?>"<?php if (!(strcmp($row_rsAirModel['aircraft_model'], ((isset($_POST["airMakeField"]))?$_POST["airMakeField"]:"")))) {echo "selected=\"selected\"";} ?>><?php echo $row_rsAirModel['aircraft_model']?>Select Aircraft Model</option>

              <?php

} while ($row_rsAirModel = mysql_fetch_assoc($rsAirModel));

  $rows = mysql_num_rows($rsAirModel);

  if($rows > 0) {

      mysql_data_seek($rsAirModel, 0);

      $row_rsAirModel = mysql_fetch_assoc($rsAirModel);

  }

?>

              </select>

This topic has been closed for replies.
Correct answer MurraySummers

Change this -

<select name="airMake" style="width: 200px;"onchange="this.form.submit();" id="airMake">

to this -

<select name="airMake" style="width: 200px;"onchange="this.form.submit();" id="airMake">

<option value="-1">Select Aircraft Manufacturer</option>

Then if the value of 'airMake' is -1 you know that no choice was made.

1 reply

MurraySummers
MurraySummersCorrect answer
Inspiring
December 15, 2011

Change this -

<select name="airMake" style="width: 200px;"onchange="this.form.submit();" id="airMake">

to this -

<select name="airMake" style="width: 200px;"onchange="this.form.submit();" id="airMake">

<option value="-1">Select Aircraft Manufacturer</option>

Then if the value of 'airMake' is -1 you know that no choice was made.

illbehereAuthor
Participant
December 19, 2011

That worked beautifully, thank you so much

Tom