473,603 Members | 2,644 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 #1
106 19752
acoder
16,027 Recognized Expert Moderator MVP
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.
Aug 15 '08 #2
bonneylake
769 Contributor
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
Aug 15 '08 #3
acoder
16,027 Recognized Expert Moderator MVP
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?
Aug 15 '08 #4
bonneylake
769 Contributor
yes the options come from the database as well.
Aug 15 '08 #5
acoder
16,027 Recognized Expert Moderator MVP
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.
Aug 15 '08 #6
bonneylake
769 Contributor
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
Aug 15 '08 #7
acoder
16,027 Recognized Expert Moderator MVP
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.
Aug 16 '08 #8
bonneylake
769 Contributor
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
Aug 18 '08 #9
acoder
16,027 Recognized Expert Moderator MVP
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.
Aug 18 '08 #10

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

Similar topics

2
6617
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. Here is a snippet of my code so far: Type AcroApp = Type.GetTypeFromCLSID(new...
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 to many fashion so that I can have the same book checked out time after time.
2
2650
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 automatically fill in the fields called "LastName" and "FirstName" into the form's text boxes. It was...
19
3975
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
2258
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 to be temporary for that specific form. When I try to type in the fields, it tells me it cannot be...
2
2506
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. (EXAMPLE- if i click to go to supplier 1's logon page, when i click that link whats suppose to be in the...
1
3609
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 ……. Registration.FirstName but it isn’t recognized what is the correct way to reference form data. Does...
3
12177
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 receives from an XML file. Not sure where I should start from. Any help is greatly appreciated. Thank...
1
3393
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. For example if I select 1000, 1100, 1200, 1300 in the list I only get 1000 in my procedure. If I...
0
7996
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8415
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8273
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6735
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5441
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3951
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2430
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
1514
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1259
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.