Skip to main content
sunilpasa
Participant
February 5, 2015
Question

Need Help to get value of selected item from Select Dropdown list in cfquery under insert query

  • February 5, 2015
  • 1 reply
  • 2391 views

Form:

<!-- Sign up FORM -->
<cfoutput>
  <form  method="post" action="HomeShow_submit.cfm">
    <input type="hidden" name="UserID" value="#RemoveChars(CGI.Auth_User, 1, Find('\', CGI.Auth_User))#">
  <input type="hidden" name="Fname" value="#User.fname#">
  <input type="hidden" name="Lname" value="#User.lname#">
  <input type="hidden" name="Year" value="#DatePart('yyyy', Now())#">
 
    <table width="600" border="0" align="center" cellpadding="1" cellspacing="1">
        <tr>
  <th colspan="2" scope="col" class="Header" align="center">Home Show Sign Up Form</th>
        </tr>

  <tr>
  <th align="left" class="red">Shifts</th>
    <td><select name="ShiftsList">
          <option value="" selected>  ... select a Shift</option>
      <cfloop query="ShiftsList">
        <option value="#ShiftsList.ShiftDetails#">#ShiftsList.ShiftDetails#</option>
      </cfloop>
    </select>
    </td>
  </tr>
     
  <tr>
  <td colspan="2" align="center"><input type="submit" NAME="SubmitForm"  value="Submit"></td>
  </tr>
    </table>
  </form>
</cfoutput>



ActionPage

-------------------

<cfquerydatasource="HomeShow"  name="InsertHomeShow">
INSERT INTO HomeShow
  VALUES
  ('#Form.USERID#',
  '#Form.Fname#',
  '#Form.Lname#',
  '#Form.Year#'
  ?

Question: This is where I need help, suppose we choose option with value =1 i.e. Friday March 20th 10.00 a.m to noon. I want to get value i.e 1 in Insert statement. So What I can write in side Insert statement to get that value. 


              )
</cfquery>

    This topic has been closed for replies.

    1 reply

    Inspiring
    February 26, 2015

    Like you have with the other form objects you can just use #form.ShiftsList#. This will return whatever the select option was when the form is posted. If you want the actual date though you will have to put this in the value attribute.

    <cfquery datasource="HomeShow"  name="InsertHomeShow">

      INSERT INTO HomeShow

      VALUES

      ('#Form.USERID#',

      '#Form.Fname#',

      '#Form.Lname#',

      '#Form.Year#',

       #form.ShiftsList#)

    </cfquery>

    I would recommend taking a look at cfqueryparam - ColdFusion, English documentation - Adobe Learning Resources as well to secure your sql.