473,574 Members | 2,617 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Auto fill form fields using coldfusion

769 Contributor
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
Aug 15 '08
106 19743
bonneylake
769 Contributor
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
Aug 18 '08 #11
acoder
16,027 Recognized Expert Moderator MVP
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.
Aug 19 '08 #12
bonneylake
769 Contributor
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



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.
Aug 19 '08 #13
bonneylake
769 Contributor
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



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.
Aug 19 '08 #14
acoder
16,027 Recognized Expert Moderator MVP
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.
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.
But wanted to also mention this one part...
For this question, ask in the relevant database forum. Which db are you using?
Aug 19 '08 #15
bonneylake
769 Contributor
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_cont acts. 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
Aug 20 '08 #16
acoder
16,027 Recognized Expert Moderator MVP
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?c ustnum=123.
Aug 20 '08 #17
bonneylake
769 Contributor
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\Deve lopment\WWWRoot \RachelB\footpr ints\form\getCl ient.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
Aug 20 '08 #18
acoder
16,027 Recognized Expert Moderator MVP
You used the data source name instead of the query name in the cfoutput tag.
Aug 20 '08 #19
bonneylake
769 Contributor
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
Aug 20 '08 #20

Sign in to post your reply or Sign up for a free account.

Similar topics

2
6616
by: John Scott | last post by:
Hi there, I have a PDF that has editable form fileds. I want to be able dynamically fill in those form fields based on values I provide to the PDF. Right now, I can create an instance of the object, open the PDF document, but can't get a handle on the JavaScript portion of the document in order to change any of the form field values. ...
1
5271
by: mikeybe | last post by:
Making a very simple library circulation database for a school project. I have a Patron Information table(patronID, first name, last name, phone) , an item information table (bookID, book title, authorfirst, author last) and a circulation file (ID, bookID, patronID, checoutdate, checkindate). Circulation file is linked to others in a one...
2
2649
by: Joanne Lewis | last post by:
I am having a great deal of difficulty with a form. Basically, I would like to enter an account # and have the account #, patient first name, and patient last name automatically fill. The form Record Source table is "InitialInfoFromSW". I want to enter an account #, have it look in another table called "AS400 Imported Data", and...
19
3969
by: Alex | last post by:
Hello list This question has probably already been asked, but let me ask again I have a mysql database to which I connect with my php scripts. The database contains articles. Name, Unit_Price and Reference Now my client needs to order 5 items, click a button and a table with 5 lines and 3 columns appears (until now easy)
1
2257
by: kelly623 | last post by:
I have a combo box to select a client name and then it fills in the rest of their information (address, city, state, phone, etc.) Each field is bound to the table where the information is stored. How can I allow the user to overwrite the information that is automatically filled in? Also I don't want the information to be stored. I just want it...
2
2505
by: mxdllc | last post by:
i would like to create an admin panel for my business. because i have 5 or 6 suppliers and to order i have to lookup which supplier it is then find the url, so to make things a little easier im going to create an admin panel. but i would like to know if its possible that when i click a link that it sends whats suppose to be in form fields....
1
3608
by: pbrooks252 | last post by:
I am very new to Macromedia Coldfusion, I have a user registration form and would like to capture / store & for debugging purposes echo (print) the form data using a CFscript. The form’s name is Registration one of the text fields name is FirstName. I am having a problem referencing the value entered into the field. My reference is as follows ……....
3
12168
by: SilverLight | last post by:
I need to write a C# windows application that can open a web page, fill in the fields and click the submit button on the web page automatically. I don't want to use the web browser control and have the web site open within my application. The windows application should launch the IE browser and navigate to a URL that the windows application...
1
3390
by: Rick Owen | last post by:
Greetings, I have a form that, when submitted, calls a plsql procedure. The form has a number of fields (text, hidden, select, radio) but the particular field that is giving me problems is a <selectwhich allows multiple selection. When I receive the form values in my procedure I getting only the first value of those that are selected. ...
0
8253
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7827
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8109
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6471
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5316
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3762
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2253
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1356
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1072
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.