Im trying to echo php values into a form, i know how to do it with the text fields.. I dont however know what to do with the menu drop down list as you cannot put a value into it.

I want php to remember the menu list item selected by the user in the same way ive done with the text fields.

<form id="form1" name="form1" method="post" action="carbon2.php">
  <label><br />
  </label>
  <p>
    <label>Country:
    <select name="Country" id="select" >
<option>Australia</option>
<option>Austria</option>
<option>Belarus</option>
<option>Belgium</option>
<option>Bulgaria</option>
<option>Croatia</option>
<option>Czech Republic</option>
<option>Denmark</option>
<option>Estonia</option>
<option>Finland</option>
<option>France</option>
<option>Germany</option>
<option>Greece</option>
<option>Hungary</option>
<option>Iceland</option>
<option>Ireland</option>
<option>Italy</option>
<option>Japan</option>
<option>Latvia</option>
<option>Lithuania</option>
<option>Luxembourg</option>
<option>Netherlands</option>
<option>New Zealand</option>
<option>Norway</option>
<option>Poland</option>
<option>Portugal</option>
<option>Romania</option>
<option>Russia</option>
<option>Slovak Republic</option>
<option>Slovenia</option>
<option>Spain</option>
<option>Sweden</option>
<option>Switzerland</option>
<option>Turkey</option>
<option>United Kingdom</option>
<option>Ukraine</option>
<option>Canada </option>
<option>United States</option>

</select>
</label>
  </p>
  <p>
    <label>No of people in your household:
    <input type="text" name="household" <?php if (isset($_POST['household'])) { ?> value="<?php echo $_POST['household']; ?>" <?php } ?>/>
    <br />
    <br />
    Electricity (kWh):
    <input type="text" name="Electricity" <?php if (isset($_POST['Electricity'])) { ?> value="<?php echo $_POST['Electricity']; ?>" <?php } ?>/>
    </label>
  per month</p>
  <p>
    <label>Natural Gas (therms):
    <input type="text" name="Natural_Gas" <?php if (isset($_POST['Natural_Gas'])) { ?> value="<?php echo $_POST['Natural_Gas']; ?>" <?php } ?>/>
    </label>
  per month</p>
  <p>
    <label>Heating Oil (litres):
    <input type="text" name="Heating_Oil" <?php if (isset($_POST['Heating_Oil'])) { ?> value="<?php echo $_POST['Heating_Oil']; ?>" <?php } ?>/>
    </label>
  per month</p>
  <p>
    <label>Propane (litres):
    <input type="text" name="Propane" <?php if (isset($_POST['Propane'])) { ?> value="<?php echo $_POST['Propane']; ?>" <?php } ?>/>
    </label>
  per month</p>
  <p>
    <label>Coal (kg):
    <input type="text" name="Coal" <?php if (isset($_POST['Coal'])) { ?> value="<?php echo $_POST['Coal']; ?>" <?php } ?>/>
    </label>
  per month</p>
  <p>
    <label>Kerosene (lites):
    <input type="text" name="Kerosene" <?php if (isset($_POST['Kerosene'])) { ?> value="<?php echo $_POST['Kerosene']; ?>" <?php } ?>/>
    </label>
  per month</p>
  <p>
    <label>Liquid Petroleum Gas (litres):
    <input type="text" name="Liquid_Petroleum_Gas" <?php if (isset($_POST['Liquid_Petroleum_Gas'])) { ?> value="<?php echo $_POST['Liquid_Petroleum_Gas']; ?>" <?php } ?>/>
    </label>
    per month</p>
  <p>
    <label>
    <input type="submit" value="Submit" />
    </label>
  </p>
</form>   

    Add this to the correct option tag:-

    selected="selected"
      benracer wrote:

      Add this to the correct option tag:-

      selected="selected"

      I understand how select for a default value is done, but what im doing is getting the form to be included in another php document after submitting the form... and what i want is for the values inputted to be pulled across to the new document.

      im not looking for default selection, using selected tag... im looking to echo the menu item selected by the user into the new document.

        Sessions perhaps?

        Or you could use $_POST['varname'] on the the page the form posts too.

          agulaid wrote:

          I understand how select for a default value is done, but what im doing is getting the form to be included in another php document after submitting the form... and what i want is for the values inputted to be pulled across to the new document.

          im not looking for default selection, using selected tag... im looking to echo the menu item selected by the user into the new document.

          Exactly the same thing: you want to have a particular option (i.e., the one picked by the user previously) pre-selected. So you set its "selected" attribute.

            benracer wrote:

            Add this to the correct option tag:-

            selected="selected"

            Hi Ben, ive made the following changes, which havent made a difference:

            <select name="Country">
            <option selected="selected">Australia</option>
            <option>Austria</option>
            <option>Belarus</option>
            <option>Belgium</option>
            <option>Bulgaria</option>
            <option>Croatia</option>
            <option>Czech Republic</option>
            <option>Denmark</option>
            <option>Estonia</option>
            <option>Finland</option>
            <option>France</option>
            <option>Germany</option>
            <option>Greece</option>
            <option>Hungary</option>
            <option>Iceland</option>
            <option>Ireland</option>
            <option>Italy</option>
            <option>Japan</option>
            <option>Latvia</option>
            <option>Lithuania</option>
            <option>Luxembourg</option>
            <option>Netherlands</option>
            <option>New Zealand</option>
            <option>Norway</option>
            <option>Poland</option>
            <option>Portugal</option>
            <option>Romania</option>
            <option>Russia</option>
            <option>Slovak Republic</option>
            <option>Slovenia</option>
            <option>Spain</option>
            <option>Sweden</option>
            <option>Switzerland</option>
            <option>Turkey</option>
            <option>United Kingdom</option>
            <option>Ukraine</option>
            <option>Canada </option>
            <option>United States</option>
            <?php if (isset($_POST['Country'])) { ?>
                 value="<?php echo $_POST['Country']; ?>"
                <?php } ?>
                </select>

              set the value within the opening select, then use an error message if nothing is selected

              <?
              	if($_POST['submit']=="send") {
                 $errcount = 0;
                 $error1="<font face='Verdana' size='2'><span style='color:red'>";
                 //...
                 //...
              
               if(preg_match('/^[a-zA-Z_ -]{2,}$/i', $_POST['country'])){
                      $Country = $_POST['Country'];     
              } else { $error1 .= " Required!"; $errcount++;
              } //plus any other validation //nb dont forget security when inputting into your database e.g. $County = mysql_real_escape_string($_POST['County']); if ($errcount !=0) { //displays errors in form boxes } else { ?> <td> <select name="Country" id="Country" style="width:145px;" value="<? echo $Country; ?>"> <option value="">Please select a Country</option> .. .. <option value = "United States">United States</option></td> <td><?php echo $error1; ?></td> <?php } ?>

              untested but something like that,

                Write a Reply...