Solved

coldfusion Form

Posted on 2006-10-24
3
147 Views
Last Modified: 2013-12-24

 I have read only access to this database(on a different server) that I am pulling data from via DATASOURCE customer..  I get all the custid in the dropdown on the form but it does not populate customername, etc when custid changes.  

I get the output though when I just do <cfoutput> #customerlist.customerID#,#customerlist.customerName#</cfoutput> etc in the code
-----------
however when I do the samething from a local database everything works fine..any ideas?

-------code below

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<html>
<head>
<cfset DATASOURCE="Customer">
<CFQUERY name="Customerlist" datasource="#DATASOURCE#">
Select * from CustomerTable
</CFQUERY>

     <title>Untitled</title>
<script language="JavaScript" type="text/javascript">
function listItem(custID, custName, custAge, custLoc, custAdd, custCity, custZip, custCntry){
          this.custID=custID;
          this.custName=custName;
          this.custAge=custAge;
          this.custLoc=custLoc;
          this.custAdd=custAdd;
          this.custCity=custCity;
          this.custZip=custZip;
          this.custCntry=custCntry;
     }


function populateCustInfo(customerID){    
     
for(x=0; x < arrItems.length; x++){
               if(arrItems[x].custID==customerID){
                  document.getElementById('txtCustomerName').value=arrItems[x].custName;
                    document.getElementById('txtCustomerAge').value=arrItems[x].custAge;
                    document.getElementById('txtCustomerLocation').value=arrItems[x].custLoc;
                    document.getElementById('txtCustomerAddress').value=arrItems[x].custAdd;
                    document.getElementById('txtCustomerCity').value=arrItems[x].custCity;
                    document.getElementById('txtCustomerZip').value=arrItems[x].custZip;
                    document.getElementById('txtCustomerCountry').value=arrItems[x].custCntry;
                    }
}
}
var arrItems = new Array();
arrItems[arrItems.length]= new listItem('0','','','','','','','');
<cfoutput query="customerList">
arrItems[arrItems.length]= new listItem
('#customerID#','#customerName#','#customerAge#','#customerLocation#','#customerAddress#','#customerCity#','#customerZipcode#','#customerCountry#');
</cfoutput>

 
</script>
</head>

<body>
<form name="myForm" method ="post" action="customerAction.cfm">
<select name="selCustId" onchange="populateCustInfo(this.value)">
<option value="0">Select</option>
<cfoutput query="customerList">
<option value="#customerId#">#customerName#</option></cfoutput>
</select>
custid
<p>
  <input type="text" value="" name="txtCustomerName">
  custname
</p>
<p>&nbsp;</p>
<p>  <input type="text" value="" name="txtCustomerAge">
  custage
</p>
<p>    <input type="text" value="" name="txtCustomerLocation">
  custloc
</p>
<p>  <input type="text" value="" name="txtCustomerAddress">
  custaddr
</p>
<p>  <input type="text" value="" name="txtCustomerCity">
  custaddress
</p>
<p>  <input type="text" value="" name="txtCustomerZip">
  custcity
</p>
<p>  <input type="text" value="" name="txtCustomerCountry">custcount </p>
<p>&nbsp;</p>
<input type="submit" value="submit" name="submit">
<input type="reset" value="reset" name="reset">

</form>
</body>
</html>
0
Comment
Question by:ohemaa
  • 2
3 Comments
 
LVL 36

Accepted Solution

by:
SidFishes earned 500 total points
ID: 17799663
"I get all the custid in the dropdown on the form but it does not populate customername, etc when custid changes.  "

unless you use ajax (or load all of the customer info for every customerid) you can't do this without a trip to the server and back






0
 

Author Comment

by:ohemaa
ID: 17803271
I am not sure how to do this.  can you pls. get me started?
0
 
LVL 36

Expert Comment

by:SidFishes
ID: 17803732
one of the easiest implementations of AJAX is called JSMX found here.. http://www.lalabird.com/

there sample code you can play with...

If that's more than you want to do you can simply do something like this:
have the customer ID select box the only part visible on the page until the customerid is selected and then post the form back to the same page which then shows the full customer detail...


<CFQUERY name="GETCustomerID" datasource="#DATASOURCE#">
Select CustomerID, CustName from CustomerTable
</CFQUERY>

<cfparam name="form.customerid" default ="">
<!--- set this so the page does throw an error when loads with no customerid --->
<form name="myForm" method ="post" action="THISPAGEName.cfm"> <!--- points the post back to this same page --->
<select Name="CustomerID">
<option value="">-- Select Customer --</option>
<cfloop query="CustomerList">
<option value="#GETcustomerID.customerID#">#GETcustomerID.custName#</option>
</cfloop>

<input type="submit" Value="Lookup Customer">
</form>

<cfif form.CustomerID NEQ ""><!--- then we've selected a customer so show it's info --->

<CFQUERY name="CustomerInfo" datasource="#DATASOURCE#">
Select * from CustomerTable where CustomerID = #form.customerID#
</CFQUERY>


Info for #CustomerInfo.customerID#<br>

<p>
  <input type="text" value="#CustomerInfo.custname#" name="txtCustomerName">

</p>
<p>&nbsp;</p>
<p>  <input type="text" value="#CustomerInfo.custage#" name="txtCustomerAge">

</p>
<p>    <input type="text" value="#CustomerInfo.custloc#" name="txtCustomerLocation">
 
</p>
<p>  <input type="text" value=" #CustomerInfo.custaddr#" name="txtCustomerAddress">

</p>
<p>  <input type="text" value="#CustomerInfo.custcity" name="txtCustomerCity">
 
</p>
<p>  <input type="text" value="#CustomerInfo.custzip" name="txtCustomerZip">

</p>
<p>  <input type="text" value="#CustomerInfo.custcountry#" name="txtCustomerCountry">custcount </p>
<p>&nbsp;</p>
<input type="submit" value="submit" name="submit">
<input type="reset" value="reset" name="reset">

</form>
</cfif>






0

Featured Post

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

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

Suggested Solutions

Article by: kevp75
Hey folks, 'bout time for me to come around with a little tip. Thanks to IIS 7.5 Extensions and Microsoft (well... really Windows 8, and IIS 8 I guess...), we can now prime our Application Pools, when IIS starts. Now, though it would be nice t…
Meet the world's only “Transparent Cloud™” from Superb Internet Corporation. Now, you can experience firsthand a cloud platform that consistently outperforms Amazon Web Services (AWS), IBM’s Softlayer, and Microsoft’s Azure when it comes to CPU and …
The purpose of this video is to demonstrate how to prevent comment spam on a WordPress Website. This will be demonstrated using a Windows 8 PC. Plugin Akismet will be used. Go to your WordPress login page. This will look like the following: myw…
The purpose of this video is to demonstrate how to set up the permalinks on a WordPress Website. This will be demonstrated using a Windows 8 PC. Go to your WordPress login page. This will look like the following: mywebsite.com/wp-login.php : Go t…

867 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now