• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 275
  • Last Modified:

get value of drowdown

ok, i have the below dropdown box.  works fine.  i'm storing the id value, but i also want to get the description that is displayed in the dropdown.  for example, i might have the following valus in my table:

id=1
desc=description1

when this dropdown displays, it shows "description1" in the dropdown, but i need to store the id for other purposes.  how can i also store the "description1" in some form of hidden form input that will allow me to submit this value to another form?

<select name="drpProgramAreaID" onchange="this.form.submit()">
<option value = "">Select Program Area</option>
    <cfloop query="qryGetProgramArea">
         <option value="#qryGetProgramArea.PROGRAM_AREA_ID#"
            <cfif isDefined('form.drpProgramAreaID')>
            <cfif form.drpProgramAreaID eq "#qryGetProgramArea.PROGRAM_AREA_ID#">
               selected
              </cfif>
          </cfif>>#qryGetProgramArea.PROGRAM_AREA_DESC#
       </option>
    </cfloop>      
</select>
0
benpung
Asked:
benpung
  • 3
  • 2
  • 2
1 Solution
 
INSDivision6Commented:
Straight approach:

<select name="drpProgramAreaID" onchange="this.form.submit()">
. . . . . .
<option value="#qryGetProgramArea.PROGRAM_AREA_ID#,#qryGetProgramArea.PROGRAM_AREA_DESC#">
. . . . .
</select>


In your calling script:

<cfset area=ListToArray(drpProgramAreaID)>

area[1] - your ID
area[2] - your description

0
 
INSDivision6Commented:
Well, assuming that decription doesn't contain comma.  If it could use another delimiter, like "~".
0
 
benpungAuthor Commented:
i'm not sure this will work because the form also refreshes to itself and i need only the number in the value at that time.  let me post the entire script that i have here and see if you can help.  as you can see after each dropdown is selected, the form submits to itself so the dropdown will only contain valid values bases on the contents of the other dropdowns.  if i put both the ID and the description in the "value" of the program area dropdown, this fails when it submits to itself.  is there a way i can parse this out prior to the submit or somethign?  i'm a CF rookie so i'm sure it's uglier than it needs to be so any suggestions are appreciated.

<CFSETTING showdebugoutput="yes">
<cfset varDbSchema = "EMS_PROCS">

<cfif isDefined('form.txtIncidentNumber')>
    <cfset page.txtIncidentNumber = form.txtIncidentNumber>
    <cfset varIncidentNumber = form.txtIncidentNumber>
<cfelse>
    <cfset varIncidentNumber = "Enter Incident">
</cfif>

<cfif isDefined('form.drpProgramAreaID')>
    <cfset page.drpProgarmAreaID = form.drpProgramAreaID>
</cfif>

<cfif isDefined('form.drpSiteNameID')>
    <cfset page.drpSiteNameID = form.drpSiteNameID>
</cfif>

<cfquery name="qry_GetIncidentFields" datasource="EMSWEB">
SELECT *
FROM #varDbSchema#.LLY_CM_INCIDENT
</cfquery>

<cfquery name="qryGetProgramArea" datasource="EMSWEB">
SELECT DISTINCT LLY_ODS_PROGRAM_AREA.PROGRAM_AREA_DESC, LLY_ODS_PROGRAM_AREA.PROGRAM_AREA_ID
FROM #varDbSchema#.LLY_ODS_PROGRAM_AREA, #varDbSchema#.LLY_CM_INCIDENT
WHERE LLY_ODS_PROGRAM_AREA.PROGRAM_AREA_ID = LLY_CM_INCIDENT.PROGRAM_AREA_ID
</cfquery>

<cfquery name="qryGetSiteName" datasource="EMSWEB">
SELECT DISTINCT LLY_ODS_SITE.SITE_NAME, LLY_ODS_SITE.SITE_NAME_ID
FROM #varDbSchema#.LLY_ODS_SITE, #varDbSchema#.LLY_CM_INCIDENT
WHERE LLY_CM_INCIDENT.SITE_NAME_ID = LLY_ODS_SITE.SITE_NAME_ID
</cfquery>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>EIMS Compliance Manager - Get Incident</title>
<script>
function postToIncidentDetail(){
     frm=document.IncidentForm;
     frm.action='Incident_Detail.cfm';
     frm.method='post';
     frm.submit();
}
</script>
</head>
<body>

<form method="post" name="IncidentForm">
<cfoutput>

<input type="text" name="txtIncidentNumber" size="15" onchange="this.form.submit()" value="#varIncidentNumber#"></input>
<br>
<br>

<!--- PROGRAM AREA DROPDOWN --->
<select name="drpProgramAreaID" onchange="this.form.submit()">
<option value = "">Select Program Area</option>
    <cfloop query="qryGetProgramArea">
         <option value="#qryGetProgramArea.PROGRAM_AREA_ID#
            <cfif isDefined('form.drpProgramAreaID')>
            <cfif form.drpProgramAreaID                eq "#qryGetProgramArea.PROGRAM_AREA_ID#">
               selected
              </cfif>
          </cfif>>#qryGetProgramArea.PROGRAM_AREA_DESC#
       </option>
    </cfloop>      
</select>

<br>
<br>

<!--- END PROGRAM AREA DROPDOWN --->

<!--- SITE NAME DROPDOWN --->
<select name="drpSiteNameID" onchange="this.form.submit()">
<option>Select Site Name</option>
  <!--- <cfif form.drpProgramAreaID IS ""> --->
  <cfif NOT isDefined('form.drpProgramAreaID')>
   <cfloop query="qryGetSiteName">
      <option value="#qryGetSiteName.SITE_NAME_ID#"
         <cfif isDefined('form.drpSiteNameID')>
            <cfif form.drpSiteNameID eq "#qryGetSiteName.SITE_NAME_ID#">
               selected
            </cfif>
         </cfif>>#qryGetSiteName.SITE_NAME#
      </option>
     </cfloop>
    <cfelse>
     <cfquery name="qryGetSiteNameWPA" datasource="EMSWEB">
      SELECT DISTINCT LLY_ODS_SITE.SITE_NAME, LLY_ODS_SITE.SITE_NAME_ID
      FROM #varDbSchema#.LLY_ODS_SITE, #varDbSchema#.LLY_CM_INCIDENT
      WHERE LLY_CM_INCIDENT.SITE_NAME_ID = LLY_ODS_SITE.SITE_NAME_ID
      AND LLY_CM_INCIDENT.PROGRAM_AREA_ID = '#form.drpProgramAreaID#'
     </cfquery>
     <cfloop query="qryGetSiteNameWPA">
      <option value="#qryGetSiteNameWPA.SITE_NAME_ID#"
         <cfif isDefined('form.drpSiteNameID')>
            <cfif form.drpSiteNameID eq "#qryGetSiteNameWPA.SITE_NAME_ID#">
               selected
            </cfif>
         </cfif>>#qryGetSiteNameWPA.SITE_NAME#
      </option>
     </cfloop>
   </cfif>  
</select>

<br>
<br>
<!--- END SITE NAME DROPDOWN --->

</cfoutput>
<br>
</p>
<input type="button" name="SubmitForm" value="Find" onClick="postToIncidentDetail()">
<input type="reset" name="ResetForm" value="Reset">
</form>
</body>
</html>
0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
INSDivision6Commented:
It will work.

<cfif isDefined('form.drpProgramAreaID')>
    <cfset drpProgarmAreaID = ListGetAt(form.drpProgramAreaID, 1)>
    <cfset progarmAreaDescription= ListGetAt(form.drpProgramAreaID, 2)>
</cfif>
0
 
mrichmonCommented:
You can also look at adding custom attributes to the dropdown list, but I have never done this is CF, but have in other languages

<option id="option#id#" value="#id#" description="#description#">#description#</option>

I would guess in the code:

#form.selectname['description']#

but am not sure if this works in CF.
0
 
mrichmonCommented:
Another option is to have javascript enter the description into a hidden form field on change of hte drop down.

Then you only have to worry about

#form.selectname# for the id
#form.hiddenfield# for the description
0
 
benpungAuthor Commented:
thanks for the help.  it's much appreciated.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 3
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now