3 Replies - 3135 Views - Last Post: 16 July 2009 - 06:07 PM Rate Topic: -----

#1 ddrumm  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 23
  • Joined: 24-February 09

Making a listbox default to last selected option

Posted 13 July 2009 - 02:50 AM

Hi
Ive a listbox in my coldfusion code, and when i preview it I get a list of name to select from, only thing is its always defaulting back to the first one.
Is there any way i can get it to stay at the last name ive selected rather than goining back to the first one

Heres the code im using for it
 <cfparam name="url.action" default="">

<cfquery name="qgetcompany" datasource="#request.dsn#">
select COMPANY_Number,COMPANY_Name
from COMPANY
ORDER BY COMPANY_Number
</cfquery>

<cfset page = "invoicesearch">
<cfset request.currentmenu = 4>
<cfinclude template="inc_header.cfm">
<style>
#midcontent td{font-size:11px;}
</style>
	<tr>
		<td id="midcontenttop">	
		<h1>Quotes</h1>
		</td>
	</tr>
	<cfoutput>
	<tr>
		<td id="midcontent">
		<table cellpadding="0" cellspacing="0">
			<tr>
				<td id="menu" valign="top">
				<cfinclude template="inc_leftmenu.cfm">
				</td>
				<td valign="top">
				<cfif listfind(valuelist(qgetglobalmenuoptions.MENUOPTIONS_KEY),request.currentmenu) eq 0>
				ACCESS DENIED
				<cfelse>
				<cfif url.action eq "updaterequest">
				<cfinclude template="scheduledtasks/processinvoice.cfm">
				</cfif>
				<fieldset>
				<legend>Search</legend>
				<table>
					<form name="search" method="post" action="dsp_searchdocs.cfm">
					<tr>
						<td>
						<select name="COMPANY_Number">
							<cfloop query="qgetcompany"><option value="#COMPANY_Number#">[#COMPANY_Number#] #COMPANY_Name#</cfloop>
						</select>
						</td>
						<td>Invoice Number : <input type="text" name="INVOICE_Number" size="12"></td>
						<td><input type="submit" value="Find " /></td>
					</tr>
					</form>
				</table>
				</fieldset>
				<cfif isdefined("form.COMPANY_Number")>
				<cfif form.INVOICE_Number eq "">
				<p>Your Search has returned 0 results</p>
				<cfelse>
				<cfquery name="qgetinvoices" datasource="#request.dsn#">
				select INVOICE_DateAdded, I.COMPANY_Number,INVOICE_Number, C.COMPANY_Name, INVOICE_Key
				from INVOICE I, COMPANY C
				where I.COMPANY_Number = C.COMPANY_Number
				AND I.COMPANY_Number = #form.COMPANY_Number#
				AND INVOICE_Number = '#form.INVOICE_Number#'
				</cfquery>
				<table cellpadding="3" width="750">
					<tr class="row4">
						<th align="left">Date</th>
						<th align="left">Company No.</th>
						<th align="left">Invoice No.</th>
						<th align="left" colspan="3">Tools</th>
					</tr>
					<cfloop query="qgetinvoices">
					<tr class="#iif(currentrow mod 2, de("row1"), de("row2"))#">
						<td>#dateformat(INVOICE_DateAdded,"dd mmm yyyy")#</td>
						<td>#COMPANY_Name#</td>
						<td>#INVOICE_Number#</td>
						<td colspan="2"><a href="pnt_invoice.cfm?invoice=#INVOICE_Key#" target="_blank">[Print]</a></td>
					</tr>
					</cfloop>
				</table>
				</cfif>	
				</cfif>
				</cfif>
				<br/>
				</td>
			</tr>
		</table>
		</td>
	</tr>
	</cfoutput>
<cfinclude template="inc_footer.cfm">	 


Thanks

Is This A Good Question/Topic? 0
  • +

Replies To: Making a listbox default to last selected option

#2 xheartonfire43x  Icon User is offline

  • D.I.C Regular

Reputation: 46
  • View blog
  • Posts: 454
  • Joined: 22-December 08

Re: Making a listbox default to last selected option

Posted 14 July 2009 - 11:52 AM

View Postddrumm, on 13 Jul, 2009 - 01:50 AM, said:

Hi
Ive a listbox in my coldfusion code, and when i preview it I get a list of name to select from, only thing is its always defaulting back to the first one.
Is there any way i can get it to stay at the last name ive selected rather than goining back to the first one

Heres the code im using for it


If you are submitting the form back to itself then just use an if statement in your option tag. <cfif isDefined('FORM.companyNumber') AND FORM.companyNumber EQ company_number>selected</cfif>
Was This Post Helpful? 0
  • +
  • -

#3 ddrumm  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 23
  • Joined: 24-February 09

Re: Making a listbox default to last selected option

Posted 16 July 2009 - 12:34 AM

View Postxheartonfire43x, on 14 Jul, 2009 - 10:52 AM, said:

If you are submitting the form back to itself then just use an if statement in your option tag. <cfif isDefined('FORM.companyNumber') AND FORM.companyNumber EQ company_number>selected</cfif>



Hi, Ive tried this but it doesnt seem to do anything for me
Was This Post Helpful? 0
  • +
  • -

#4 xheartonfire43x  Icon User is offline

  • D.I.C Regular

Reputation: 46
  • View blog
  • Posts: 454
  • Joined: 22-December 08

Re: Making a listbox default to last selected option

Posted 16 July 2009 - 06:07 PM

View Postddrumm, on 15 Jul, 2009 - 11:34 PM, said:

Hi, Ive tried this but it doesnt seem to do anything for me


<select name="COMPANY_Number">
	<cfloop query="qgetcompany">
		<option value="#COMPANY_Number#" <cfif isDefined('FORM.COMPANY_Number') AND (FORM.COMPANY_Number EQ COMPANY_Number)>selected</cfif>>
			   [#COMPANY_Number#] #COMPANY_Name#
		</option>
</cfloop>
</select>



If you copy that directly into your code that should work.
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1