Using MySQL value as default for Drop Down List of Form

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • hdhouse3rd
    New Member
    • Mar 2010
    • 3

    Using MySQL value as default for Drop Down List of Form

    Greetings:
    A newbie question. I have a form that is completed and every time we save the form the value of the drop down list is reset to default. I presume you need to do a query of the database and challenge with drop down list to make that the primary field.

    Here is the code I have so far:

    Code:
        <td colspan="2" id="c180">Water Source:
          <select name="water_source" size="1" id="water_source" style="height:15px width:67px" value="<?php echo $water_source1; ?>">
            <option value=""></option>
            <option value="Drilled">Drilled</option>
            <option value="Burrowed">Burrowed</option>
            <option value="Public">Public</option>
            <option value="Spring">Spring</option>
          </select></td>
    I appreciate your help in advance.

    Henry
    Last edited by Dormilich; Mar 10 '10, 05:54 PM. Reason: Please use [code] tags when posting code
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    Originally posted by hdhouse3rd
    I have a form that is completed and every time we save the form the value of the drop down list is reset to default.
    that’s sensible, the form is needed for input (not output) in the first place. so once the form has been processed, there is no need to keep the data (unless you do combo boxes).

    Comment

    • hdhouse3rd
      New Member
      • Mar 2010
      • 3

      #3
      Guess I should clarify better. Reset to default on a new form is not a problem. However, if I pull the same form id up again the value on the form changes from what was previously set to default.

      What I need to occur is that value that is stored in the "water_sour ce" field of the MySQL record becomes the new default for the field.

      Could someone direct me to a resource or suggest how the code could be edited to use the value previously stored in the record as the new default when the form is edited?

      Hope that makes sense. I am learning this on the fly, regular programmer is out on sick leave.

      Comment

      • Dormilich
        Recognized Expert Expert
        • Aug 2008
        • 8694

        #4
        set the selected attribute for that <option> which is now the default (as of your query)

        Comment

        • hdhouse3rd
          New Member
          • Mar 2010
          • 3

          #5
          The selected attribute gives me the default for the field, which is fine.

          However, if there is a value stored in the database, I would like this to become the new default.

          As per my code example above:
          If "Drilled" is the default, but for the retrieved record "Spring" is already associated with the record, I would like "Spring" to be the default. If there is no value present then "Drilled" or a NULL field would be fine.

          Thanks in advance.

          Comment

          Working...