Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

cfselect onchange or onselect to populate a field via Access dbase query

Posted on 2005-05-10
6
Medium Priority
?
3,627 Views
Last Modified: 2013-12-24
I'm creating a form that has a dropdown of items to order and I need the price associated with this item to populate the price field.  The dropdown is a cfselect populated with options from an Access database (the prices are here too).  I want the onchange or onselect to query the same database and populate the price field with the price associated with the hardware selected.  There are four dropdowns on the same page that need the same functionality.

Here a portion of the code that I have so far; I removed my poor attempts at adding in the onchange or onselect.  I think that these events need to hit a second page with the query, passing through the hardware selected as the condition in the query and pass that price back through to the main page (or I'm just babbling).

<html>
<head>
<cfquery name="hardware" datasource="mydatabase">
SELECT *
FROM options
WHERE type IN ('hardware', 'none')
ORDER BY description
</cfquery>
</head>

<body>
<cfform action="form.cfm" method="post" name="proposal" id="proposal">
<table>
  <tr>
    <td><cfselect name="hardware" size="1" query="hardware" display="description" value="part_number" selected="none"></cfselect></td>
    <td><input type="text" name="hardware_qty" size="3" value="1"></td>
    <td><input type="hidden" name="hardware_price" value="#hardware_price#"><font face="arial" size="2"><b>&nbsp;$#hardware_price#</b></font></td>
</tr>
</table>
</cfform>
</body>
</html>

Thank you in advance for any help provided,
Brian
0
Comment
Question by:chignoli
  • 2
  • 2
  • 2
6 Comments
 
LVL 35

Assisted Solution

by:mrichmon
mrichmon earned 1800 total points
ID: 13974029
It sounds like you need a background lookup and related select boxes

See these threads and let me know if you have further questions

Thread for related select boxes:
http://www.experts-exchange.com/Web/WebDevSoftware/ColdFusion/Q_21292451.html

Thread for doing the lookup in the backgroud:
http://www.experts-exchange.com/Web/WebDevSoftware/ColdFusion/Q_20936125.html



It should be very easy to combine
0
 
LVL 20

Assisted Solution

by:trailblazzyr55
trailblazzyr55 earned 200 total points
ID: 13975746
here's a good tutorial on dynamic drop downs and pretty easy to follow if the links above don't help...

http://tutorial166.easycfm.com/

this may also simplify what you're trying to do, this will dynamically populate your drop-downs without refreshing your page, it's a custom tag on macromedia.com..
here's the link:

http://www.macromedia.com/cfusion/exchange/index.cfm?view=sn131&extID=1000288#loc=en_us&view=sn131&extID=1000288&viewName=ColdFusion%20Extension&avm=1

it's free and may reduce some hassle.. I think this is what you're looking to do :o)

Regards,
~trail
0
 
LVL 20

Expert Comment

by:trailblazzyr55
ID: 13975750
you can also use the custom tag on macromedia as a cf_tag or cfmodule.. depends on the use :o)

0
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

 

Author Comment

by:chignoli
ID: 13982494
mrichmon - I think that I almost have your background lookup working, but it is getting caught on passing the text portion of the variable back through to the function on the main page.  My code is below:

I used your iFrameRPC.js code...

------Main Page------
<html>
<head>
<script type="text/javascript" language="JavaScript" src="iframeRPC.js"></script>
<script type="text/javascript" language="JavaScript">
function LookupHardware()
{
     var hardware = eval("document.proposal.hardware").value;
         
     if (hardware != "none")
     {     // If a Hardware was entered then look it up in our DB
          callToServer("HardwareLookup.cfm?hardware=" + escape(hardware))
     }
}
function HardwareLookupComplete(hardware, Found, hardware_price)
{    
     if(Found)
     {     // Hardware in DB so fill in data
          eval("document.proposal.hardware_price").value = hardware_price
     }
     return;
}
</script>
</head>

<body>
<cfquery name="hardware" datasource="MyDatabase">
SELECT *
FROM options
WHERE type IN ('hardware', 'none')
ORDER BY description
</cfquery>

<cfform action="verify.cfm" method="post" name="proposal" id="proposal">
<table>
  <tr>
    <td><cfselect name="hardware" size="1" query="hardware" display="description" value="part_number" selected="none" onchange="LookupHardware()"></cfselect></td>
    <td><input type="text" name="hardware_qty" size="3" value="1"></td>
    <td><input type="text" name="hardware_price" id="hardware_price" size="10" disabled></td>
  </tr>
</table>
</body>
</html>

------Lookup Page------
<cfquery datasource="MyDatabase" name="LookupHardware">
     SELECT *
     FROM options
     WHERE part_number = <cfqueryparam cfsqltype="cf_sql_varchar" value="#hardware#">
</cfquery>

<cfif LookupHardware.RecordCount EQ 0>
     <cfset Found = false><!--- Did not find Hardware; set other fields to blank --->
     <cfset hardware_price = "">
<cfelse>
     <cfset Found = true><!--- Found Hardware; set other fields to DB values --->
     <cfset hardware_price = "LookupHardware.price">
</cfif>

<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<cfoutput>
<body onLoad="window.parent.HardwareLookupComplete(#URL.hardware#, #Found#, '#hardware_price#');">
</body>
</cfoutput>
</html>

The script error is:
Line: 16
Char: 1
Error: 'M197' is undefined
Code: 0
URL: http://www.xxx.com/form/HardwareLookup.cfm?hardware=M197-570-14-US1

trail - Thanks for the TwoSelectsRelated.cfm link, that will help me on a different site :)

Thank you for your help,
Brian
0
 
LVL 35

Accepted Solution

by:
mrichmon earned 1800 total points
ID: 13982661
You most likely need to escape the hardware on the way back as well or put in single quotes (or both) since you have letters, numbers, and dashes

<body onLoad="window.parent.HardwareLookupComplete('#URL.hardware#', #Found#, '#hardware_price#');">

0
 

Author Comment

by:chignoli
ID: 13988975
Thank you for your help and the code!
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is a guide to setting up a new WHM/cPanel Server to be used for web hosting accounts. It is intended for web hosting company administrators and dedicated server owners. For under $99 per month (considering normal rate of Big Data Cetnters like …
A web service (http://en.wikipedia.org/wiki/Web_service) is a software related technology that facilitates machine-to-machine interaction over a network. This article helps beginners in creating and consuming a web service using the ColdFusion Ma…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Suggested Courses

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question