Combo box triggers query

using a combo box selection as a query

Page 1 of 1

4 Replies - 4904 Views - Last Post: 24 September 2009 - 11:44 AM Rate Topic: -----

#1 midasxl  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 188
  • Joined: 03-December 08

Combo box triggers query

Post icon  Posted 15 September 2009 - 10:53 AM

Greetings!

Check this out...

<cfoutput>
<form name="myForm" id="myForm" method="post">
<SELECT NAME="pickMe">
<cfloop query="marksTest">
<OPTION value="#marksTest.EXPLOIT#">#UCase(marksTest.EXPLOIT)#</OPTION>
</cfloop>
</SELECT>
</form>
</cfoutput>

<cfif isDefined("form.pickMe")>

<cfquery name="marksTest" dbType="query">
   SELECT *
   FROM myquery
</cfquery>

<cfdump var="#marksTest#">

</cfif>



What I am trying to accomplish is that when the user makes a choice from the combo box it is used to perform a query. Am I on the right track here? Any tips or suggestions will be greatly appreciated. Thanks!

Is This A Good Question/Topic? 0
  • +

Replies To: Combo box triggers query

#2 _Leonard_  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 07-September 09

Re: Combo box triggers query

Posted 16 September 2009 - 12:50 AM

Hi midasxl,

You ask if you are on the right track. Are you getting error messages or something else happening that makes you think things are not working?

_Leonard_
Was This Post Helpful? 0
  • +
  • -

#3 midasxl  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 188
  • Joined: 03-December 08

Re: Combo box triggers query

Posted 16 September 2009 - 05:50 AM

Hi _Leonard_, thanks for your reply.

Actually nothing happens at all. When I make a selection from the combo box, there is absolutely no action on the page. So apparently the if statement is not seeing me make the selection.
Was This Post Helpful? 0
  • +
  • -

#4 _Leonard_  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 07-September 09

Re: Combo box triggers query

Posted 16 September 2009 - 07:47 PM

Hi midasxl,

Ok thanks for the additional. Wanted to make sure I had all pertinent information, so as not to miss something. Since nothing is happening, I am suspecting that you have your <cfif> structure wrong.

Give the code below a try and I believe you will have better results. You should be able to copy and paste the code below into a .cfm page, change appropriate information as needed and be good to go.

_Leonard_


<cfif IsDefined('form.btn_submit')>

	<!--- Begin - Evaluation if a selection was made --->
	<cfif IsDefined('form.pickMe') AND Trim(form.pickMe) eq "None Selected">
		<!--- Insert no selection made information below here --->
		<p>You did not make a selection</p>

	<cfelse>
		<!--- Insert cfoutput processing code below here --->
		<p><cfoutput>
		#form.pickMe#
		</cfoutput></p>

	</cfif>
	<!--- End - Evaluation if a selection was made --->

<cfelse>

	<!--- Begin - Form element section --->

	<cfquery name="marksTest" dbType="query">
	   SELECT *
	   FROM myquery
	</cfquery>

	<cfform action="pickme_test.cfm" method="post" enctype="application/x-www-form-urlencoded" name="pickme" preloader="no" id="myForm" lang="en" dir="ltr">
		<div style="clear: both; padding: 15px 0px 0px 0px">
			<cfselect enabled="yes" name="pickMe" size="1" id="pickMe" dir="ltr" lang="en" tooltip="Make a selection from the list" multiple="no" >
				<option value="None Selected" selected="selected">- Make a selection -</option>
				<cfoutput query="marksTest">
				<option value="#marksTest.EXPLOIT#">#UCase(marksTest.EXPLOIT)#</OPTION>
				</cfoutput>
			</cfselect>
		</div>
		
		<div style="clear: both; padding: 15px 0px 0px 0px">
			<div style="clear: both; float: left; padding: 0px `0px 0px 0px`">
				<cfinput type="submit" name="btn_submit" id="btn_submit" style="cursor: pointer;" dir="ltr" lang="en" value="SUBMIT">
			</div>
			<div style="float: left">
				<cfinput type="reset" name="btn_reset" id="btn_reset" style="cursor: pointer;" dir="ltr" lang="en" value="CLEAR">
			</div>
		</div>
	</cfform>

	<!--- End - Form element section --->

</cfif>



Was This Post Helpful? 0
  • +
  • -

#5 midasxl  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 188
  • Joined: 03-December 08

Re: Combo box triggers query

Posted 24 September 2009 - 11:44 AM

_Leonard_,
Thanks for the assistance. Check out what I ended up using. I took alot of your suggestions and morphed them with some of my own additional research and came up with this...

<cfscript>
	ws=CreateObject("webservice", "pathToComponent.cfc?wsdl");
	getData = ws.myData();
</cfscript>

<form name="myForm" id="myForm" method="post" action="">
	<SELECT NAME="pickMe" onchange="this.form.submit()">
		<OPTION value="SELECT EXPLOIT NAME">
			SELECT EXPLOIT NAME
		</OPTION>
	<cfloop query="getData">
		<OPTION value="#getData.EXPLOIT#" <cfif isDefined('form.pickMe') AND form.pickMe eq "#getData.EXPLOIT#"> selected="selected" </cfif>>
			#getData.EXPLOIT#
		</OPTION>
	</cfloop>
	</SELECT>
</form>
</cfoutput>

<!--- Checks dropdown value is defined and is not the default value before calling the webservice exploitData function. Argument "exploit" uses RTrim() function to remove extra whitespace. Argument "query" is the return result from previous call to the webservice myData function. The returned query's data is used to populate a table. --->
<cfif isDefined('form.pickMe') AND form.pickMe neq "SELECT EXPLOIT NAME">
	<cfscript>
		getExploitData = ws.exploitData(exploit="#RTrim(form.pickMe)#", query="#getData#");
	</cfscript>
	
	<cfoutput>	
	
	<p>You selected: #form.pickMe#</p>
		<table>
			<tr>
				<th>Exploit Name</th>
				<th>Three Qtrs Back</th>
				<th>Two Qtrs Back</th>
				<th>One Qtr Back</th>
				<th>Current</th>
			</tr>
			<tr class="spark">
				<td>#getExploitData.Exploit#</td>
				<td>#getExploitData.ThreeBack#</td>
				<td>#getExploitData.TwoBack#</td>
				<td>#getExploitData.OneBack#</td>
				<td>#getExploitData.Current#</td>
			</tr>
		</table>
	</cfoutput>
</cfif>



The web service application that is called in the script tags does a database query and returns data from the following column names: Exploit, ThreeBack, TwoBack, Oneback, and Current. This works well for me. Hope others may find it useful as well. Thanks!!

This post has been edited by midasxl: 25 September 2009 - 06:06 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1