0

Is it possible to set a select inputs default value based on a value returned by a database query? Where below getFormData.color_it = 'RAL7035TXT'

<cfquery name="getFormData" datasource="RC">
        SELECT      *
        FROM        RFQ_Data
        WHERE       form_ID = <cfqueryparam value="#ARGUMENTS.rfqID#">
    </cfquery>

<select name="color_it">
<option value="RAL9005TXT">RAL9005TXT </option>
<option value="RAL7035TXT">RAL7035TXT </option>
<option value="other">Other </option>
</select>

The result I am looking for would change the select so that the option with the value RAL7035TXT would be on top so it is the default. (see below)

<select name="color_it">
<option value="RAL7035TXT">RAL7035TXT </option>
<option value="RAL9005TXT">RAL9005TXT </option>
<option value="other">Other </option>
</select>

Would this have to be done with with a lot of if statements?

Looks like my question was answered in one of my other questions: ColdFusion how to set form input values from the results of a cfquery?

Community
  • 1
  • 1
Denoteone
  • 4,043
  • 21
  • 96
  • 150

1 Answers1

0

You can set default selected value:

<select name="color_it">
<option value="RAL7035TXT"selected="selected" >RAL7035TXT </option>
<option value="RAL9005TXT">RAL9005TXT </option>
<option value="other">Other </option>
</select>

If you want to use value in the select that is received by the database you can just save the query in a php variable and use this value in the tag like this:

<option value="<?php echo $value; ?>"><?php echo $value; ?></option>
Atanas44
  • 3
  • 3
  • This thought process would work but I also want to keep the other options in case the user wants to make a change to their previous selection. – Denoteone Apr 21 '15 at 07:05
  • You can put as many as you like and not all must be from the database. What – Atanas44 Apr 21 '15 at 07:11