Help | Site Map
Connecting Tech Pros Worldwide
Reply
 
LinkBack Thread Tools
  #1  
Old August 15th, 2008, 03:24 PM
Site Addict
 
Join Date: Aug 2008
Location: United States
Posts: 679
Default Auto fill form fields using coldfusion

Hey Everyone,

Well i don't know if my question should be in javascript/ajax or coldfusion, i figure this is more of a coldfusion question. But if this is in the wrong section let me know an all gladly delete my question an put it in the correct section.

Well what i am trying to do is pretty simple. I have a input field and someone starts typing in a customer number. As they type in the customer number the drop down box is populated. They then click on the drop down box an the rest of the form is populated (it gets all the information from a database).

I found a script online that does almost exactly what i want to do except it is in php. I have found an example of this in every language except coldfusion and well i must admit i am not good at converting code from one language to another.

But anyway i was wondering if anyone could provide me with an example on how i would do this in coldfusion instead of php? or if you know of a tutorial,forum, or example online i could look at?

Here is the example page
http://www.dhtmlgoodies.com/scripts/...nt-lookup.html

an here is the code
http://www.dhtmlgoodies.com/index.ht..._client_lookup

i already created the drop down box part of this (since it is missing in the
the example above), but like i said i just can't figure out how i would populate it using my coldfusion database. Here is what i got for the drop down box

here is coldfusion/html
Expand|Select|Wrap|Line Numbers
  1. <cfquery name="getcustnum" datasource="CustomerSupport">
  2. usp_CS_Getcontacts
  3. </cfquery>
  4. <HTML>
  5. <HEAD>
  6.     <TITLE>JavaScript Toolbox - Auto-Complete</TITLE>
  7. <SCRIPT LANGUAGE="JavaScript" SRC="autocomplete.js"></SCRIPT>
  8. </HEAD>
  9. <BODY BGCOLOR=#FFFFFF LINK="#00615F" VLINK="#00615F" ALINK="#00615F">
  10. <FORM>
  11. Customer Number*
  12. <INPUT TYPE="text" NAME="input1" VALUE="" ONKEYUP="autoComplete(this,this.form.options,'value',true)" onChange="validate(this.form.custnum,'Customer Number')">
  13. <SELECT NAME="options" 
  14. onChange="this.form.input1.value=this.options[this.selectedIndex].value" onclick="">
  15. <cfoutput query="getcustnum">
  16. <option value="#fk_custNum#">#fk_custNum#</option>
  17. </cfoutput>
  18. </SELECT>
  19. Company Name:<input type="text" name="compname"  size="20" id="compname"/>
  20. First Name:<input type="text" name="fname"  size="20" id="fname"/>
  21. Last Name:<input type="text" name="lname"size="20" id="lname"/>
  22. </FORM>
  23. </BODY>
  24. </HTML>

here is the javascript
Expand|Select|Wrap|Line Numbers
  1. function autoComplete (field, select, property, forcematch) {
  2.     var found = false;
  3.     for (var i = 0; i < select.options.length; i++) {
  4.     if (select.options[i][property].toUpperCase().indexOf(field.value.toUpperCase()) == 0) {
  5.         found=true; break;
  6.         }
  7.     }
  8.     if (found) { select.selectedIndex = i; }
  9.     else { select.selectedIndex = -1; }
  10.     if (field.createTextRange) {
  11.         if (forcematch && !found) {
  12.             field.value=field.value.substring(0,field.value.length-1); 
  13.             return;
  14.             }
  15.         var cursorKeys ="8;46;37;38;39;40;33;34;35;36;45;";
  16.         if (cursorKeys.indexOf(event.keyCode+";") == -1) {
  17.             var r1 = field.createTextRange();
  18.             var oldValue = r1.text;
  19.             var newValue = found ? select.options[i][property] : oldValue;
  20.             if (newValue != field.value) {
  21.                 field.value = newValue;
  22.                 var rNew = field.createTextRange();
  23.                 rNew.moveStart('character', oldValue.length) ;
  24.                 rNew.select();
  25.                 }
  26.             }
  27.         }
  28.     }
But thank you in advance :),
Rach
Reply
  #2  
Old August 15th, 2008, 04:20 PM
acoder's Avatar
Site Moderator
 
Join Date: Nov 2006
Location: UK
Posts: 12,722
Default

For the populating of the dropdown box and the text boxes, you will need JavaScript. If you're having problems with that part, start a new thread in the JavaScript forum.

For getting the values from the database, you will obviously need Coldfusion. If you want to convert that PHP file to Coldfusion, it's not that difficult, though I don't like how it's done. There's a better way if you're interested.
Reply
  #3  
Old August 15th, 2008, 04:56 PM
Site Addict
 
Join Date: Aug 2008
Location: United States
Posts: 679
Default

Hey Acoder,

definately interested if you have a better way to go about getting the values from the database. I think i can figure out the javascript part, just very lost on the coldfusion part.

Thanks in advance,
Rach
Reply
  #4  
Old August 15th, 2008, 05:09 PM
acoder's Avatar
Site Moderator
 
Join Date: Nov 2006
Location: UK
Posts: 12,722
Default

The better way would involve not outputting JavaScript to be eval-ed as in the example you linked to. You can output HTML to be inserted directly, or XML or JSON to be parsed.

From what you've described, it seems you're going to make two requests. One to populate the drop down and the second one to populate the fields. Are the options from a database too?
Reply
  #5  
Old August 15th, 2008, 05:17 PM
Site Addict
 
Join Date: Aug 2008
Location: United States
Posts: 679
Default

yes the options come from the database as well.
Reply
  #6  
Old August 15th, 2008, 07:19 PM
acoder's Avatar
Site Moderator
 
Join Date: Nov 2006
Location: UK
Posts: 12,722
Default

You'll need to files then. Let's deal with populating the drop down first.

You have a simple query which gets the values for the options, then you use cfloop to loop over and display the options, e.g.
Expand|Select|Wrap|Line Numbers
  1. <cfloop ...>
  2. <option value="<cfoutput>#val#</cfoutput>"><cfoutput>#opttext#</cfoutput>
  3. </cfloop>
then in your client-side code, you just set the innerHTML of the select element. An alternative is to output XML or JSON which you can parse.
Reply
  #7  
Old August 15th, 2008, 08:14 PM
Site Addict
 
Join Date: Aug 2008
Location: United States
Posts: 679
Default

Acoder,

Well i sorta understand what your saying. But wanted to ask would this drop down i had already created work? because this gets the information from the table for the drop down the way i have it, just kinda curious what the difference is.

Expand|Select|Wrap|Line Numbers
  1. <cfquery name="getcustnum" datasource="CustomerSupport">
  2. usp_CS_Getcontacts
  3. </cfquery>
  4.  
  5. <SELECT NAME="options" >
  6. <cfoutput query="getcustnum">
  7. <option value="#fk_custNum#">#fk_custNum#</option>
  8. </cfoutput>
  9. </SELECT>
an with the innerHTML i am a bit baffled on how i would go about that. But i am going to do some research on what you have said :).

But thank you for all the help you have given me :)
Rach
Reply
  #8  
Old August 16th, 2008, 01:29 PM
acoder's Avatar
Site Moderator
 
Join Date: Nov 2006
Location: UK
Posts: 12,722
Default

Oh I see. So you already have that working. In that case, you only need to make one request onchange. Now what you output in the Coldfusion file depends on how you're going to code the client-side JavaScript part. You could use XML or JSON, or you could just output a string delimited by a special character and use the split() method in JavaScript to split the string into an array to fill the separate fields.
Reply
  #9  
Old August 18th, 2008, 03:29 PM
Site Addict
 
Join Date: Aug 2008
Location: United States
Posts: 679
Default

Hey Acoder,

Sorry for the slow response. Well the only thing i am not understanding is the coldfusion side of this. I am pretty sure i could figure out the javascript side if i understood the coldfusion side.

What i am confused on is how would i get that information from the database? Like the only stored procedures i have created so far is a insert and a update. An i am use to having my form on one page an click submit an takes me to another page to insert (i am still very new to coldfusion as you can tell).I don't know if this would help but this is my cfquery for inserting the contact which shows the felds i am dealing with

Expand|Select|Wrap|Line Numbers
  1. <cfquery name="insertcontacts" datasource="CustomerSupport">
  2. exec usp_CS_Insertcontacts  '#Form.custnum#','#Form.compname#','#Form.fname#',
  3. '#Form.lname#','#Form.address#','#Form.city#','
  4. #Form.state#','#Form.zip#','#Form.email#','#Form.priphone#',
  5. '#Form.secphone#','#Form.custnotes#'
  6. </cfquery>
but sorry if this don't make much since, been a long weekend. If you need me to explain anymore just ask an all gladely try to.

Thank you very much for all the help,
Rach
Reply
  #10  
Old August 18th, 2008, 07:25 PM
acoder's Avatar
Site Moderator
 
Join Date: Nov 2006
Location: UK
Posts: 12,722
Default

You need a select query and pass in the customer number, e.g. #url.custnum#, so when you make an Ajax request, say getCustDetails.cfm?custnum=123, the code would output the values.
Reply
  #11  
Old August 18th, 2008, 08:13 PM
Site Addict
 
Join Date: Aug 2008
Location: United States
Posts: 679
Default

Hey Acoder,

I am trying. but i must admit this is way over my head. I am pretty new to coldfusion an javascript combined an i must admit i am really lost.This is what i have done, which i know it don't work or is right. But this is how much i am understanding.

Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript">
  2. function add(){
  3. <cfquery name="custnum" datasource="CustomerSupport">
  4. select * from tbl_CS_contacts
  5. where fk_custNum=fk_custnum
  6. </cfquery>
  7. }
  8. </script>
  9. <SELECT NAME="options" onclick="javascript:add();">
  10. <cfoutput query="getcustnum">
  11. <option value="#fk_custNum#">#fk_custNum#</option>
  12. </cfoutput>
  13. </SELECT>
  14. Company Name:<input type="text" name="compname"  size="20" id="compname"/>
  15. First Name:<input type="text" name="fname"  size="20" id="fname"/>
  16. Last Name:<input type="text" name="lname"size="20" id="lname"/>
  17.  
but wanted to ask if you knew of a website that could explain select query better to me? or even a suggested way i could search for my problem online? because i must admit i am very lost.

Thanks again,
Rach
Reply
  #12  
Old August 19th, 2008, 11:21 AM
acoder's Avatar
Site Moderator
 
Join Date: Nov 2006
Location: UK
Posts: 12,722
Default

Let's start at the beginning then. You've got something that works, so let's use that instead. Coldfusion can only run while the page is loading, not afterwards (unless you use Ajax to call a separate Coldfusion page). Let's get that working first, then you can worry about the JavaScript later.

The "custnum" query is fine except that it should be on a separate page (rather like the PHP file) and you need to use ## signs to refer to the passed value, e.g.
Expand|Select|Wrap|Line Numbers
  1. <cfquery name="custnum" datasource="CustomerSupport">
  2. select * from tbl_CS_contacts
  3. where fk_custNum=#url.custnum#
  4. </cfquery>
Then use cfoutput to loop over the query to output the values. This file you can call getClient.cfm to replace getClient.php.
Reply
  #13  
Old August 19th, 2008, 07:12 PM
Site Addict
 
Join Date: Aug 2008
Location: United States
Posts: 679
Default

Acoder,

First off thank you for all the patience you are having with me, really appreciate it :).

Ok so i tried to do what you said (not at work today so i can't test it). But here is what i came up with, this is on my getClient.cfm page

Expand|Select|Wrap|Line Numbers
  1.  <cfquery name="custnum" datasource="CustomerSupport">
  2. select * from tbl_CS_contacts
  3. where fk_custNum=#url.custnum#
  4. </cfquery>
  5.  
  6. <cfoutput query = "CustomerSupport">
  7. #compname#
  8. #fname#
  9. #lname#
  10. #add1#
  11. #city#
  12. #state#
  13. #zip#
  14. #email#
  15. #pri_phone#
  16. #sec_phone#
  17. #notes#
  18. </cfoutput>

I am not sure if i did this right (if i didn't i am sorry in advance). But i was wondering when i do the cfoutput query inbetween like where i have #fname# is that suppose to be the name of the column in the database or is it suppose to be the name of the field in the form? because when i do a stored procedure an i do an insert i am use to doing #Form.(name i gave the input)#.

An also wanted to ask do i need to put fk_custNum in the cfoutput as well? An well not sure if i did the loop part right, use to doing it a very different way. But i looked up what you said an it said this loops through the query. This is the example of the website i found http://livedocs.adobe.com/coldfusion...s/tags-b12.htm

But wanted to also mention this one part, probably should of mentioned it earlyer. but i been trying to do it by myself before asking for help.what i am trying to do is create a stored procedure for the contacts table that if the customer number already exists it wont create a record in the table, but if it doesn't exist it will create a record in the table (trying to prevent duplicates). But wanted to ask if what we are doing on will affect this or if i need the stored procedure before this? an also wanted to ask if you knew of an example that does something similar to what i am doing, was thinking about trying if exists, an looked up if exists. but most of the examples show if exists create other wise update an don't need it to update.

But thank you in advance for all the help an the patience you are having with me you have no idea how much i appreciate this :) Thank you
Rach



Quote:
Originally Posted by acoder
Let's start at the beginning then. You've got something that works, so let's use that instead. Coldfusion can only run while the page is loading, not afterwards (unless you use Ajax to call a separate Coldfusion page). Let's get that working first, then you can worry about the JavaScript later.

The "custnum" query is fine except that it should be on a separate page (rather like the PHP file) and you need to use ## signs to refer to the passed value, e.g.
Expand|Select|Wrap|Line Numbers
  1. <cfquery name="custnum" datasource="CustomerSupport">
  2. select * from tbl_CS_contacts
  3. where fk_custNum=#url.custnum#
  4. </cfquery>
Then use cfoutput to loop over the query to output the values. This file you can call getClient.cfm to replace getClient.php.
Reply
  #14  
Old August 19th, 2008, 10:32 PM
Site Addict
 
Join Date: Aug 2008
Location: United States
Posts: 679
Default

Acoder,

First off thank you for all the patience you are having with me, really appreciate it :).

Ok so i tried to do what you said (not at work today so i can't test it). But here is what i came up with, this is on my getClient.cfm page

Expand|Select|Wrap|Line Numbers
  1.  <cfquery name="custnum" datasource="CustomerSupport">
  2. select * from tbl_CS_contacts
  3. where fk_custNum=#url.custnum#
  4. </cfquery>
  5.  
  6. <cfoutput query = "CustomerSupport">
  7. #compname#
  8. #fname#
  9. #lname#
  10. #add1#
  11. #city#
  12. #state#
  13. #zip#
  14. #email#
  15. #pri_phone#
  16. #sec_phone#
  17. #notes#
  18. </cfoutput>

I am not sure if i did this right (if i didn't i am sorry in advance). But i was wondering when i do the cfoutput query inbetween like where i have #fname# is that suppose to be the name of the column in the database or is it suppose to be the name of the field in the form? because when i do a stored procedure an i do an insert i am use to doing #Form.(name i gave the input)#.

An also wanted to ask do i need to put fk_custNum in the cfoutput as well? An well not sure if i did the loop part right, use to doing it a very different way. But i looked up what you said an it said this loops through the query. This is the example of the website i found http://livedocs.adobe.com/coldfusion...s/tags-b12.htm

But wanted to also mention this one part, probably should of mentioned it earlyer. but i been trying to do it by myself before asking for help.what i am trying to do is create a stored procedure for the contacts table that if the customer number already exists it wont create a record in the table, but if it doesn't exist it will create a record in the table (trying to prevent duplicates). But wanted to ask if what we are doing on will affect this or if i need the stored procedure before this? an also wanted to ask if you knew of an example that does something similar to what i am doing, was thinking about trying if exists, an looked up if exists. but most of the examples show if exists create other wise update an don't need it to update.

But thank you in advance for all the help an the patience you are having with me you have no idea how much i appreciate this :) Thank you
Rach



Quote:
Originally Posted by acoder
Let's start at the beginning then. You've got something that works, so let's use that instead. Coldfusion can only run while the page is loading, not afterwards (unless you use Ajax to call a separate Coldfusion page). Let's get that working first, then you can worry about the JavaScript later.

The "custnum" query is fine except that it should be on a separate page (rather like the PHP file) and you need to use ## signs to refer to the passed value, e.g.
Expand|Select|Wrap|Line Numbers
  1. <cfquery name="custnum" datasource="CustomerSupport">
  2. select * from tbl_CS_contacts
  3. where fk_custNum=#url.custnum#
  4. </cfquery>
Then use cfoutput to loop over the query to output the values. This file you can call getClient.cfm to replace getClient.php.
Reply
  #15  
Old August 19th, 2008, 10:37 PM
acoder's Avatar
Site Moderator
 
Join Date: Nov 2006
Location: UK
Posts: 12,722
Default

Quote:
Originally Posted by bonneylake
But i was wondering when i do the cfoutput query inbetween like where i have #fname# is that suppose to be the name of the column in the database or is it suppose to be the name of the field in the form?
The name of the column in the table.
Quote:
Originally Posted by bonneylake
An also wanted to ask do i need to put fk_custNum in the cfoutput as well?
The loop looks OK, but will need to be modified for use in the JavaScript. Try this page on its own without Ajax with example input (custnum=***) and see what you get.
Quote:
Originally Posted by bonneylake
But wanted to also mention this one part...
For this question, ask in the relevant database forum. Which db are you using?
Reply
  #16  
Old August 20th, 2008, 02:30 PM
Site Addict
 
Join Date: Aug 2008
Location: United States
Posts: 679
Default

Acoder,

i just got one question about the try to do this without ajax. Ok so am i suppose to be using the dropdown i created or am i suppose to be using the link i had put at the beginning of my question http://www.dhtmlgoodies.com/scripts/...nt-lookup.html ?

i tried to do it using my dropdown but i really don't know how i would do this.

here is what i tried
Expand|Select|Wrap|Line Numbers
  1. <cfquery name="getcustnum" datasource="CustomerSupport">
  2. usp_CS_Getcontacts
  3. </cfquery>
  4.  
  5.  
  6. <HTML>
  7. <HEAD>
  8.     <TITLE>JavaScript Toolbox - Auto-Complete</TITLE>
  9. <SCRIPT LANGUAGE="JavaScript" SRC="autocomplete.js"></SCRIPT>
  10. <script type="text/javascript">
  11.  
  12. </script>
  13. </HEAD>
  14. <BODY BGCOLOR=#FFFFFF LINK="#00615F" VLINK="#00615F" ALINK="#00615F">
  15. <FORM action="getClient.cfm" method="POST">
  16. Customer Number*
  17. <INPUT TYPE="text" NAME="input1" VALUE="" ONKEYUP="autoComplete(this,this.form.options,'value',true)" onChange="validate(this.form.custnum,'Customer Number')">
  18. <SELECT NAME="options" 
  19. onChange="this.form.input1.value=this.options[this.selectedIndex].value" onclick="javascript:add();">
  20. <cfoutput query="getcustnum">
  21. <option value="#fk_custNum#">#fk_custNum#</option>
  22. </cfoutput>
  23. </SELECT>
  24. Company Name:<input type="text" name="compname"  size="20" id="compname"/>
  25. First Name:<input type="text" name="fname"  size="20" id="fname"/>
  26. Last Name:<input type="text" name="lname"size="20" id="lname"/>
  27. </FORM>
  28. </BODY>
  29. </HTML>
an the table i am using is dbo.tbl_CS_contacts. I mean i created a stored procedure that inserts i just can't figure out how to make it where if the customer id already exist don't insert. This is what i got so far

Expand|Select|Wrap|Line Numbers
  1. set ANSI_NULLS ON
  2. set QUOTED_IDENTIFIER ON
  3. go
  4.  
  5.  
  6.  
  7.  
  8. -- =============================================
  9. -- Author:        <Author,,Name>
  10. -- Create date: <Create Date,,>
  11. -- Description:    <Description,,>
  12. -- =============================================
  13. ALTER PROCEDURE [dbo].[usp_CS_Insertcontacts]
  14.     -- Add the parameters for the stored procedure here
  15.       (@fk_custNum nvarchar(50),
  16.        @cust_company nvarchar(75),
  17.        @fname nvarchar(50),
  18.        @lname nvarchar(50),
  19.        @add1 nvarchar(50),
  20.        @city nvarchar(50),
  21.        @state nvarchar(5),
  22.        @zip nvarchar(15),
  23.        @email nvarchar(100),
  24.        @pri_phone nvarchar(15),
  25.        @sec_phone nvarchar(15),
  26.        @notes nvarchar(500)
  27. )
  28. AS
  29. declare @pk_contactID nvarchar(55)
  30. set @pk_contactID = (select max_num from tbl_CS_ID_HELPER where table_name='tbl_CS_contacts')
  31. update tbl_CS_ID_helper set max_num=max_num+1 where table_name='tbl_CS_contacts'
  32. BEGIN
  33.     -- SET NOCOUNT ON added to prevent extra result sets from
  34.     -- interfering with SELECT statements.
  35.     SET NOCOUNT ON;
  36.  
  37.     -- Insert statements for procedure here
  38.  
  39. insert into tbl_CS_contacts
  40. (pk_contactID,fk_custNum,cust_company,fname,lname,add1,city,state,
  41. zip,email,pri_phone,sec_phone,notes)
  42.  
  43. values
  44. (@pk_contactID,@fk_custNum,@cust_company,@fname,@lname,@add1,@city,@state,
  45. @zip,@email,@pri_phone,@sec_phone,@notes)
  46.  
  47. select @pk_contactID as contactID
  48. END
Thanks in advance,
Rach
Reply
  #17  
Old August 20th, 2008, 04:28 PM
acoder's Avatar
Site Moderator
 
Join Date: Nov 2006
Location: UK
Posts: 12,722
Default

You can test by just typing into your address bar, e.g. say a valid custnum is 123, then you'd test by typing http://pathtosite/getClient.cfm?custnum=123.
Reply
  #18  
Old August 20th, 2008, 04:56 PM
Site Addict
 
Join Date: Aug 2008
Location: United States
Posts: 679
Default

Acoder,

Ok i tested it. An well i get this.

QUERY

The QUERY attribute of the tag does not specify the name of an available query

The error occurred while processing an element with a general identifier of (CFOUTPUT), occupying document position (5:7) to (5:42) in the template file C:\Inetpub\Development\WWWRoot\RachelB\footprints\ form\getClient.cfm.


but here is the code i got in the getClient.cfm file.
Expand|Select|Wrap|Line Numbers
  1. <cfquery name="custnum" datasource="CustomerSupport">
  2.       select * from tbl_CS_contacts
  3.       where fk_custNum=#url.custnum#
  4.       </cfquery>
  5.       <cfoutput query = "CustomerSupport">
  6.       #cust_company#
  7.       #fname#
  8.       #lname#
  9.       #add1#
  10.       #city#
  11.       #state#
  12.       #zip#
  13.       #email#
  14.       #pri_phone#
  15.       #sec_phone#
  16.       #notes#
  17.       </cfoutput>
which does fk_custNum need to be in the cfoutput?but where to go from here?

Thank you,
Rach
Reply
  #19  
Old August 20th, 2008, 06:00 PM
acoder's Avatar
Site Moderator
 
Join Date: Nov 2006
Location: UK
Posts: 12,722
Default

You used the data source name instead of the query name in the cfoutput tag.
Reply
  #20  
Old August 20th, 2008, 06:58 PM
Site Addict
 
Join Date: Aug 2008
Location: United States
Posts: 679
Default

Acoder,

All i can say is wow that is impressive!!! I have tried so many times to just use cfoutput query (for other projects) an never had any luck an surely thought it would never work but its awesome to see it work!!! No errors an worked like a charm. but that is pretty cool i never thought you could do that wow! But ok what is next??? i am so excited now lol.

Thank you for all the help i am learning so much :)
Rach
Reply
  #21  
Old August 20th, 2008, 09:11 PM
acoder's Avatar
Site Moderator
 
Join Date: Nov 2006
Location: UK
Posts: 12,722
Default

The next step is to output what the Ajax/JavaScript code expects, e.g. in the PHP file:
Expand|Select|Wrap|Line Numbers
  1. echo "formObj.firstname.value = '".$inf["firstname"]."';\n"; 
would become
Expand|Select|Wrap|Line Numbers
  1. formObj.firstname.value = "#firstname#";
and so on.
Reply
  #22  
Old August 20th, 2008, 09:33 PM
Site Addict
 
Join Date: Aug 2008
Location: United States
Posts: 679
Default

Acoder

ok so this is what i got in getClient.cfm

Expand|Select|Wrap|Line Numbers
  1. <cfquery name="custnum" datasource="CustomerSupport">
  2.       select * from dbo.tbl_CS_contacts
  3.       where fk_custNum=#url.custnum#
  4.       </cfquery>
  5.       <cfoutput query = "custnum">
  6.       #cust_company#
  7.       #fname#
  8.       #lname#
  9.       #add1#
  10.       #city#
  11.       #state#
  12.       #zip#
  13.       #email#
  14.       #pri_phone#
  15.       #sec_phone#
  16.       #notes#
  17.       </cfoutput>
  18.  
  19.       if {
  20.       formObj.custnum.value = "#custnum#";
  21.       formObj.compname.value = "#compname#";
  22.       formObj.fname.value = "#fname#";
  23.       formObj.lname.value = "#lname#";
  24.       formObj.address.value = "#address#";
  25.       formObj.city.value = "#city#";
  26.       formObj.state.value = "#state#";
  27.       formObj.zip.value = "#zip#";
  28.       formObj.email.value = "#email#";
  29.       formObj.priphone.value = "#priphone#";
  30.       formObj.secphone.value = "#secphone#";
  31.       formObj.custnotes.value = "#custnotes#";
  32.       custnotes
  33.       }
  34.        else {
  35.       formObj.custnum.value = "";
  36.       formObj.compname.value = "";
  37.       formObj.fname.value = "";
  38.       formObj.lname.value = "";
  39.       formObj.address.value = "";
  40.       formObj.city.value = "";
  41.       formObj.state.value = "";
  42.       formObj.zip.value = "";
  43.       formObj.email.value = "";
  44.       formObj.priphone.value = "";
  45.       formObj.secphone.value = "";
  46.       formObj.custnotes.value = "";
  47.       }
  48.  
i know theres still something missing to it. i was trying to figure it out look at the php. the only thing i think i am missing is this.

Expand|Select|Wrap|Line Numbers
  1. if(isset($_GET['getClientId'])){  
  2.   $res = mysql_query("select * from ajax_client where clientID='".$_GET['getClientId']."'") or die(mysql_error());
  3.   if($inf = mysql_fetch_array($res)){
but not sure how to convert this part to coldfusion. like everything past mysql_error is what i feel like i am missing because i see select an know i got select in what i have now. But is there anything else that needs to be added to this.

Thank you,
Rach
Reply
  #23  
Old August 20th, 2008, 09:48 PM
acoder's Avatar
Site Moderator
 
Join Date: Nov 2006
Location: UK
Posts: 12,722
Default

Not quite like that. The code that you have in if { ...} needs to replace the cfoutput query code. The rest (setting empty string) is when custnum is not set or the query returns no records.
Reply
  #24  
Old August 21st, 2008, 03:11 PM
Site Addict
 
Join Date: Aug 2008
Location: United States
Posts: 679
Default

Acoder,

alright so does that me the empty strings need to be in the cfoutput query as well?this is what i got. anything else it needs?

Expand|Select|Wrap|Line Numbers
  1. <cfquery name="custnum" datasource="CustomerSupport">
  2.       select * from dbo.tbl_CS_contacts
  3.       where fk_custNum=#url.custnum#
  4.       </cfquery>
  5.       <cfoutput query = "custnum">
  6.       if {
  7.       formObj.custnum.value = "#custnum#";
  8.       formObj.compname.value = "#compname#";
  9.       formObj.fname.value = "#fname#";
  10.       formObj.lname.value = "#lname#";
  11.       formObj.address.value = "#address#";
  12.       formObj.city.value = "#city#";
  13.       formObj.state.value = "#state#";
  14.       formObj.zip.value = "#zip#";
  15.       formObj.email.value = "#email#";
  16.       formObj.priphone.value = "#priphone#";
  17.       formObj.secphone.value = "#secphone#";
  18.       formObj.custnotes.value = "#custnotes#";
  19.       custnotes
  20.       }
  21.        else {
  22.       formObj.custnum.value = "";
  23.       formObj.compname.value = "";
  24.       formObj.fname.value = "";
  25.       formObj.lname.value = "";
  26.       formObj.address.value = "";
  27.       formObj.city.value = "";
  28.       formObj.state.value = "";
  29.       formObj.zip.value = "";
  30.       formObj.email.value = "";
  31.       formObj.priphone.value = "";
  32.       formObj.secphone.value = "";
  33.       formObj.custnotes.value = "";
  34.       }
  35.       </cfoutput>
Thank you again,
Rach
Reply
  #25  
Old August 21st, 2008, 03:24 PM
acoder's Avatar
Site Moderator
 
Join Date: Nov 2006
Location: UK
Posts: 12,722
Default

No, there's no "if { ... } else {..." in Coldfusion unless using cfscript. In Coldfusion you have <cfif> and <cfelse>. Also don't forget that you need conditions.

Use cfparam to default to the empty string on url.custnum. In the cfif you need to check that url.custnum is not empty and also that the query recordcount is not 0. If both those conditions are met, then you can output the values from the query, otherwise set all the form fields to empty in the cfelse part.

Note: some of this stuff is basic. It might be a good idea to go through some tutorials, e.g. the ones on the Adobe website.
Reply
  #26  
Old August 21st, 2008, 04:49 PM
Site Addict
 
Join Date: Aug 2008
Location: United States
Posts: 679
Default

Acoder,

I have a coldfusion book that i have been using. An i have read most of the book . I have only been doing coldfusion (and javascript) for a few months an only know the extreme basics. An i have been trying my best to understand an do everything best i can based on what i got. I have dealt with both cfif and cfparam before but i must admit i am stuck on how to do it as you are describing.

This is what i tried with cfparam
Expand|Select|Wrap|Line Numbers
  1. <cfparam name="custnum" default="?url.custnum">
with the cfif i am going to do some more research. i believe i know how to check if custnum is empty but completely baffled on how to check the recordcount with it.

but thank you for the help,
Rach
Reply
  #27  
Old August 21st, 2008, 05:53 PM
acoder's Avatar
Site Moderator
 
Join Date: Nov 2006
Location: UK
Posts: 12,722
Default

The cfparam would be something like:
Expand|Select|Wrap|Line Numbers
  1. <cfparam name="url.custnum" default="">
For checking the recordcount, just use queryname.RecordCount (see link for CF8).
Reply
  #28  
Old August 21st, 2008, 07:11 PM
Site Addict
 
Join Date: Aug 2008
Location: United States
Posts: 679
Default

Acoder,

Ok i thought of a few ways i thought this could be done but unsure which way would be correct (or if any correct). Also was not sure if i was suppose to use isDefined or if i was suppose to use cfif custnum eq "". But here is a few ways i thought of.


way 1
Expand|Select|Wrap|Line Numbers
  1.  <cfoutput = "custnum">
  2.       <cfif isDefined("custnum")> 
  3. *fields*
  4.       <cfelse>
  5. *fields*
  6.       </cfif>
  7.       </cfoutput>
way 2
Expand|Select|Wrap|Line Numbers
  1. <cfoutput = "custnum">
  2.       <cfif custnum.recordcount IS 0> 
  3. *fields*
  4.       <cfelse>
  5. *fields*
  6.       </cfif>
  7.       </cfoutput>
way 3
Expand|Select|Wrap|Line Numbers
  1. <cfoutput = "custnum">
  2.       <cfif isDefined("custnum")> 
  3. *fields*
  4.       <cfelse custnum.recordcount IS 0>
  5. *fields*
  6.       </cfif>
  7.       </cfoutput>
way4
Expand|Select|Wrap|Line Numbers
  1.  <cfoutput = "custnum">
  2.       <cfif> 
  3. *fields*
  4.       <cfelse custnum eq "">
  5. *fields*
  6.       </cfif>
  7.       </cfoutput>
i even thought of maybe i could do something like