By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,833 Members | 2,067 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,833 IT Pros & Developers. It's quick & easy.

Auto fill form fields using coldfusion

100+
P: 769
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

✓ answered by acoder

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?

Share this Question
Share on Google+
106 Replies


acoder
Expert Mod 15k+
P: 16,027
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

100+
P: 769
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
Expert Mod 15k+
P: 16,027
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

100+
P: 769
yes the options come from the database as well.
Aug 15 '08 #5

acoder
Expert Mod 15k+
P: 16,027
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

100+
P: 769
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
Expert Mod 15k+
P: 16,027
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

100+
P: 769
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
Expert Mod 15k+
P: 16,027
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

100+
P: 769
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
Expert Mod 15k+
P: 16,027
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

100+
P: 769
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

100+
P: 769
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
Expert Mod 15k+
P: 16,027
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

100+
P: 769
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
Aug 20 '08 #16

acoder
Expert Mod 15k+
P: 16,027
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.
Aug 20 '08 #17

100+
P: 769
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
Aug 20 '08 #18

acoder
Expert Mod 15k+
P: 16,027
You used the data source name instead of the query name in the cfoutput tag.
Aug 20 '08 #19

100+
P: 769
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

acoder
Expert Mod 15k+
P: 16,027
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.
Aug 20 '08 #21

100+
P: 769
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
Aug 20 '08 #22

acoder
Expert Mod 15k+
P: 16,027
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.
Aug 20 '08 #23

100+
P: 769
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
Aug 21 '08 #24

acoder
Expert Mod 15k+
P: 16,027
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.
Aug 21 '08 #25

100+
P: 769
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
Aug 21 '08 #26

acoder
Expert Mod 15k+
P: 16,027
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).
Aug 21 '08 #27

100+
P: 769
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
Expand|Select|Wrap|Line Numbers
  1. <cfset custnum = custnum.recordCount>
but would any of these ways work?

Thank you for all the help :),
Rach
Aug 21 '08 #28

acoder
Expert Mod 15k+
P: 16,027
You need something like this:
Expand|Select|Wrap|Line Numbers
  1. <cfif ...>
  2. <cfoutput query="custnum">
  3. ...
  4. </cfoutput>
  5. <cfelse>
  6. ...
  7. </cfif>
You don't need isDefined because of cfparam, so NEQ "" is enough and add the check for recordcount too in the cfif.
Aug 21 '08 #29

100+
P: 769
ok here is what i tried.
Expand|Select|Wrap|Line Numbers
  1.   <cfif custnum NEQ "" custnum.recordcount IS 0> 
  2.       <cfoutput query= "custnum">
  3. *fields*
  4.    </cfoutput>
  5.       <cfelse>
  6. fields*
  7. </cfif>
  8.  
but i know i need something between cfif custnum NEQ "" and custnum.recordcount. Do i need to do something like

Expand|Select|Wrap|Line Numbers
  1. cfif custnum NEW"" or "custnum.recordcount IS 0
thinking its between or an is. but not sure which.

Thank you,
Rach
Aug 21 '08 #30

acoder
Expert Mod 15k+
P: 16,027
It's actually AND. Also, look at the logic. You want the custnum query to return something so the check should be that it's not 0.
Aug 21 '08 #31

100+
P: 769
Hey Acoder,

Ok here is what i got now, is this right?
Expand|Select|Wrap|Line Numbers
  1. <cfif custnum NEQ "" AND custnum.recordcount IS NOT 0> 
  2.       <cfoutput query= "custnum">
  3.       formObj.custnum.value = "#custnum#";
  4.       formObj.compname.value = "#compname#";
  5.       formObj.fname.value = "#fname#";
  6.       formObj.lname.value = "#lname#";
  7.       formObj.address.value = "#address#";
  8.       formObj.city.value = "#city#";
  9.       formObj.state.value = "#state#";
  10.       formObj.zip.value = "#zip#";
  11.       formObj.email.value = "#email#";
  12.       formObj.priphone.value = "#priphone#";
  13.       formObj.secphone.value = "#secphone#";
  14.       formObj.custnotes.value = "#custnotes#";
  15.  </cfoutput>
  16.       <cfelse>
  17.   formObj.custnum.value = "";
  18.       formObj.compname.value = "";
  19.       formObj.fname.value = "";
  20.       formObj.lname.value = "";
  21.       formObj.address.value = "";
  22.       formObj.city.value = "";
  23.       formObj.state.value = "";
  24.       formObj.zip.value = "";
  25.       formObj.email.value = "";
  26.       formObj.priphone.value = "";
  27.       formObj.secphone.value = "";
  28.       formObj.custnotes.value = "";
  29.       </cfif>
Thank you :),
Rach
Aug 21 '08 #32

acoder
Expert Mod 15k+
P: 16,027
That should be url.custnum, not custnum unless you've set custnum to url.custnum somewhere. Test the page again as you did earlier but this time wth invalid input too and see if it works.
Aug 21 '08 #33

100+
P: 769
Acoder,


ok when i typed in 111 (which forgot i didn't have 111 in my database) i got this

Expand|Select|Wrap|Line Numbers
  1. formObj.custnum.value = ""; formObj.compname.value = ""; formObj.fname.value = ""; formObj.lname.value = ""; formObj.address.value = ""; formObj.city.value = ""; formObj.state.value = ""; formObj.zip.value = ""; formObj.email.value = ""; formObj.priphone.value = ""; formObj.secphone.value = ""; formObj.custnotes.value = ""; 
  2.  
however, when i typed in a number that is in my database i got this

Expand|Select|Wrap|Line Numbers
  1. Error Diagnostic Information
  2. Expression result cannot be converted to a string
  3.  
  4. Expressions used inside tags like CFOUTPUT, CFQUERY, CFMAIL, etc. must evaluate to a value that can be converted to a string for output or dynamic text accumulation purposes. Complex objects, such as queries, arrays, and COM/DCOM objects, cannot be represented as strings.
  5.  
  6. The error occurred while processing an element with a general identifier of (#custnum#), occupying document position (9:32) to (9:40) in the template file 

an here is the full getClient.cfm

Expand|Select|Wrap|Line Numbers
  1. <cfparam name="url.custnum" default="">
  2.  
  3. <cfquery name="custnum" datasource="CustomerSupport">
  4.       select * from dbo.tbl_CS_contacts
  5.       where fk_custNum=#url.custnum#
  6.       </cfquery>
  7.           <cfif url.custnum NEQ "" AND custnum.recordcount IS NOT 0> 
  8.       <cfoutput query= "custnum">
  9.       formObj.custnum.value = "#custnum#";
  10.       formObj.compname.value = "#compname#";
  11.       formObj.fname.value = "#fname#";
  12.       formObj.lname.value = "#lname#";
  13.       formObj.address.value = "#address#";
  14.       formObj.city.value = "#city#";
  15.       formObj.state.value = "#state#";
  16.       formObj.zip.value = "#zip#";
  17.       formObj.email.value = "#email#";
  18.       formObj.priphone.value = "#priphone#";
  19.       formObj.secphone.value = "#secphone#";
  20.       formObj.custnotes.value = "#custnotes#";
  21.        </cfoutput>
  22.       <cfelse>
  23.       formObj.custnum.value = "";
  24.       formObj.compname.value = "";
  25.       formObj.fname.value = "";
  26.       formObj.lname.value = "";
  27.       formObj.address.value = "";
  28.       formObj.city.value = "";
  29.       formObj.state.value = "";
  30.       formObj.zip.value = "";
  31.       formObj.email.value = "";
  32.       formObj.priphone.value = "";
  33.       formObj.secphone.value = "";
  34.       formObj.custnotes.value = "";
  35.       </cfif>
Thank you :),
Rach
Aug 21 '08 #34

acoder
Expert Mod 15k+
P: 16,027
That'll be caused by the #custnum# column value. Rename the query to another name, e.g. customerdetails, then change lines 7 and 8 to use that name.
Aug 21 '08 #35

100+
P: 769
Acoder,

Ok i get the error

Expand|Select|Wrap|Line Numbers
  1. Error Diagnostic Information
  2. ODBC Error Code = 37000 (Syntax error or access violation)
  3.  
  4. [Microsoft][ODBC SQL Server Driver][SQL Server]Incorrect syntax near '='.
  5.  
  6. SQL = "select * from dbo.tbl_CS_contacts where fk_custNum="
  7.  
  8. Data Source = "CUSTOMERSUPPORT"
  9.  
  10. The error occurred while processing an element with a general identifier of (CFQUERY), occupying document position (3:1) to (3:55) in the template file C:\Inetpub\Development\WWWRoot\RachelB\footprints\form\getClient.cfm
.

an heres the code. do i need to name the url.custnum do i need to change the custnum part to customerd?

Expand|Select|Wrap|Line Numbers
  1. <cfparam name="url.custnum" default="">
  2.  
  3. <cfquery name="customerd" datasource="CustomerSupport">
  4.       select * from dbo.tbl_CS_contacts
  5.       where fk_custNum=#url.custnum#
  6.       </cfquery>
  7.           <cfif url.custnum NEQ "" AND customerd.recordcount IS NOT 0> 
  8.       <cfoutput query= "customerd">
  9.       formObj.custnum.value = "#custnum#";
  10.       formObj.compname.value = "#compname#";
  11.       formObj.fname.value = "#fname#";
  12.       formObj.lname.value = "#lname#";
  13.       formObj.address.value = "#address#";
  14.       formObj.city.value = "#city#";
  15.       formObj.state.value = "#state#";
  16.       formObj.zip.value = "#zip#";
  17.       formObj.email.value = "#email#";
  18.       formObj.priphone.value = "#priphone#";
  19.       formObj.secphone.value = "#secphone#";
  20.       formObj.custnotes.value = "#custnotes#";
  21.        </cfoutput>
  22.       <cfelse>
  23.       formObj.custnum.value = "";
  24.       formObj.compname.value = "";
  25.       formObj.fname.value = "";
  26.       formObj.lname.value = "";
  27.       formObj.address.value = "";
  28.       formObj.city.value = "";
  29.       formObj.state.value = "";
  30.       formObj.zip.value = "";
  31.       formObj.email.value = "";
  32.       formObj.priphone.value = "";
  33.       formObj.secphone.value = "";
  34.       formObj.custnotes.value = "";
  35.       </cfif>
Thank you,
Rach
Aug 21 '08 #36

acoder
Expert Mod 15k+
P: 16,027
Check that the query is correct by testing in SQL Server. In post #18, the query was slightly different.
Aug 22 '08 #37

100+
P: 769
Acoder,

Ok think i got it now. I had some of the fields named wrong. But here is what i get when i try a number (that has all the fields filled out)

Expand|Select|Wrap|Line Numbers
  1. formObj.custnum.value = "555"; formObj.cust_company.value = "test"; formObj.fname.value = "test"; formObj.lname.value = "test"; formObj.add1.value = "test"; formObj.city.value = "test"; formObj.state.value = "test"; formObj.zip.value = "test"; formObj.email.value = "test"; formObj.pri_phone.value = "test"; formObj.sec_phone.value = "test"; formObj.notes.value = "test"; 
an here is what all of getClient.cfm looks like

Expand|Select|Wrap|Line Numbers
  1. <cfparam name="url.custnum" default="">
  2.  
  3. <cfquery name="customerd" datasource="CustomerSupport">
  4.       select * from dbo.tbl_CS_contacts
  5.       where fk_custNum=#url.custnum#
  6.       </cfquery>
  7.           <cfif url.custnum NEQ "" AND customerd.recordcount IS NOT 0> 
  8.       <cfoutput query="customerd">
  9.       formObj.custnum.value = "#custnum#";
  10.       formObj.cust_company.value = "#cust_company#";
  11.       formObj.fname.value = "#fname#";
  12.       formObj.lname.value = "#lname#";
  13.       formObj.add1.value = "#add1#";
  14.       formObj.city.value = "#city#";
  15.       formObj.state.value = "#state#";
  16.       formObj.zip.value = "#zip#";
  17.       formObj.email.value = "#email#";
  18.       formObj.pri_phone.value = "#pri_phone#";
  19.       formObj.sec_phone.value = "#sec_phone#";
  20.       formObj.notes.value = "#notes#";
  21.        </cfoutput>
  22.       <cfelse>
  23.       formObj.custnum.value = "";
  24.       formObj.cust_company.value = "";
  25.       formObj.fname.value = "";
  26.       formObj.lname.value = "";
  27.       formObj.add1.value = "";
  28.       formObj.city.value = "";
  29.       formObj.state.value = "";
  30.       formObj.zip.value = "";
  31.       formObj.email.value = "";
  32.       formObj.pri_phone.value = "";
  33.       formObj.sec_phone.value = "";
  34.       formObj.notes.value = "";
  35.       </cfif>
Whats next?

Thank you :),
Rach
Aug 22 '08 #38

acoder
Expert Mod 15k+
P: 16,027
Well, with this you should be able to plug it in in place of getClient.php in the scripts that you linked to in the first post (as long as the form fields are correct).
Aug 22 '08 #39

100+
P: 769
Hey Acoder,

Well i tried doing it but can't seem to get it right so i got a few questions.

ok in the javascript part there is this line

Expand|Select|Wrap|Line Numbers
  1. ajax.requestFile = 'getClient.cfm?getClientId='+clientId;    
an was wondering after the ? what would i add? would i put #url.custnum#="+clidentid;?

an during the rest of this code do i need to change everything from clientID to custnum or am i suppose to be changing them to another name?

here is what the code looks like

Expand|Select|Wrap|Line Numbers
  1. var ajax = new sack();
  2.     var currentClientID=false;
  3.     function getClientData()
  4.     {
  5.         var clientId = document.getElementById('clientID').value.replace(/[^0-9]/g,'');
  6.         if(clientId.length==4 && clientId!=currentClientID){
  7.             currentClientID = clientId
  8.             ajax.requestFile = 'getClient.cfm?getClientId='+clientId;    // Specifying which file to get
  9.             ajax.onCompletion = showClientData;    // Specify function that will be executed after file has been found
  10.             ajax.runAJAX();        // Execute AJAX function            
  11.         }
  12.     }
  13.  
  14.     function showClientData()
  15.     {
  16.         var formObj = document.forms['clientForm'];    
  17.         eval(ajax.response);
  18.     }
  19.  
  20.     function initFormEvents()
  21.     {
  22.         document.getElementById('clientID').onblur = getClientData;
  23.         document.getElementById('clientID').focus();
  24.     }
  25.  
  26.     window.onload = initFormEvents;
  27.  

Thank you for all the help you have given me i really do appreciate it :),
Rach
Aug 22 '08 #40

acoder
Expert Mod 15k+
P: 16,027
You just have to change "getClientId" to "custnum".
Aug 22 '08 #41

100+
P: 769
Hey Acoder,

I tried what you said an i got nothing. Could it be because of the form i have?
here is what the javascript looks like now

Expand|Select|Wrap|Line Numbers
  1.     <script type="text/javascript">
  2.  
  3. var ajax = new sack();
  4.     var currentClientID=false;
  5.     function getClientData()
  6.     {
  7.         var clientId = document.getElementById('clientID').value.replace(/[^0-9]/g,'');
  8.         if(clientId.length==4 && clientId!=currentClientID){
  9.             currentClientID = clientId
  10.             ajax.requestFile = 'getClient.cfm?custnum='+clientId;    // Specifying which file to get
  11.             ajax.onCompletion = showClientData;    // Specify function that will be executed after file has been found
  12.             ajax.runAJAX();        // Execute AJAX function            
  13.         }
  14.  
  15.     }
  16.  
  17.     function showClientData()
  18.     {
  19.         var formObj = document.forms['page1'];    
  20.         eval(ajax.response);
  21.     }
  22.  
  23.  
  24.     function initFormEvents()
  25.     {
  26.         document.getElementById('clientID').onblur = getClientData;
  27.         document.getElementById('clientID').focus();
  28.     }
  29.  
  30.  
  31.     window.onload = initFormEvents;
  32.     </script>
an heres what my form looks like
Expand|Select|Wrap|Line Numbers
  1. <form name="page1" action="saveticket1.cfm" method="POST">
  2. <input type="text" name="custnum" id="clientID" value="" />
  3. <input type="text" name="compname" id="cust_company" value="" size="20"/>
  4. <input type="text" name="fname" id="fname" value="" size="20"/>
  5. <input type="text" name="lname" id="lname" value="" size="20"/>
  6. <input type="text" name="address" value="" id="add1" size="20"/>
  7. <input type="text" name="city" id="city" value="" size="20"/>
  8. <input type="text" name="state" id="state" value="" size="20"/>
  9. <input type="text" name="zip" id="zip" value="" size="20"/>
  10. <input type="text" name="email" id="email" value="" size="20"/>
  11. <input type="text" name="priphone" id="pri_phone"value="" size="20"/>
  12. <input type="text" name="secphone" id="sec_phone" value="" size="20"/>
  13. <textarea  maxlength='500' onkeyup='return ismaxlength(this)' onkeydown='return ismaxlength(this)' rows="4" cols="60" name="custnotes" id="notes" value=""></textarea>
  14.  <input type="submit" value="Submit" class="officalsubmit"/>
  15.  </form>
Any suggestions? Thank you :)
Rach
Aug 22 '08 #42

acoder
Expert Mod 15k+
P: 16,027
What's the length of the customer number that you're testing with? On line 8:
Expand|Select|Wrap|Line Numbers
  1. if(clientId.length==4 && clientId!=currentClientID){
if the clientId is less than 1000, it won't do anything. If you want any number then remove that condition.
Aug 22 '08 #43

100+
P: 769
Acoder,

The number i been trying is 444 but none of the fields are being filled in or nothing (an no errors). Here is what the code looks like now with the length taken out

Expand|Select|Wrap|Line Numbers
  1. var ajax = new sack();
  2.     var currentClientID=false;
  3.     function getClientData()
  4.     {
  5.         var clientId = document.getElementById('clientID').value.replace(/[^0-9]/g,'');
  6.             currentClientID = clientId
  7.             ajax.requestFile = 'getClient.cfm?custnum='+clientId;    // Specifying which file to get
  8.             ajax.onCompletion = showClientData;    // Specify function that will be executed after file has been found
  9.             ajax.runAJAX();        // Execute AJAX function            
  10.  
  11.     }
  12.  
  13.     function showClientData()
  14.     {
  15.         var formObj = document.forms['page1'];    
  16.         eval(ajax.response);
  17.     }
  18.  
  19.  
  20.     function initFormEvents()
  21.     {
  22.         document.getElementById('clientID').onblur = getClientData;
  23.         document.getElementById('clientID').focus();
  24.     }
  25.  
  26.  
  27.     window.onload = initFormEvents;
Thank you,
Rach
Aug 22 '08 #44

acoder
Expert Mod 15k+
P: 16,027
Is 444 a valid customer number? Does it return any data if you try it out as earlier? What about 555 which returned some test data?
Aug 22 '08 #45

100+
P: 769
Hey Acoder,

I got it to work! But its really strange. Ok when i was testing earlier i typed in the word test into the custnum (wont let me submit without a value in there).but anyway when i went to test it the way we were testing i typed in 444 and i got Conversion failed when converting the nvarchar value 'test' to data type int. The weird thing is there 2 separate records one is 444 (with its fields) and the other is test(with its fields). An now i am wondering, if the customer number is say a4t6 is it going to have a problem with this?

An also wanted to ask. I really need to make it a drop down box for the value. Like example they start typing in the input and the drop down field populates (based on the input). this part i can figure out (have already done it). but how would i make it populate the rest of the fields by clicking on the correct number in the drop down rather then after i type in the number into the field and pressenter? from the way the code works (with what we got) couldn't i put on my dropdown box like this

Expand|Select|Wrap|Line Numbers
  1. onclick="document.getElementById('clientID').onblur = getClientData"; 
or would i need to do it this way

Expand|Select|Wrap|Line Numbers
  1. onclick="document.getElementById('clientID').focus()";
this part appears in the function initFormEvents() ok thinking about it i could even do it this way

Expand|Select|Wrap|Line Numbers
  1. onclick="javascript:initFormEvents()";
here is an example of what i am trying to do (without the populating rest of fields part)

http://www.mattkruse.com/javascript/autocomplete/index.html


Thank you,
Rach
Aug 22 '08 #46

acoder
Expert Mod 15k+
P: 16,027
For the first question, can you give more details. It seems like a database problem.

For the second question, you want to call the function onchange:
Expand|Select|Wrap|Line Numbers
  1. <select id="options" name="options">
Expand|Select|Wrap|Line Numbers
  1. document.getElementById("options").onchange = getClientData;
Aug 22 '08 #47

100+
P: 769
Acoder,

alrighty all try to explain this best i can, i am even baffled by this myself.
Basically i had a record in the database called test. for example

Expand|Select|Wrap|Line Numbers
  1. pk_contact id    fk_custnum....(other fields)
  2. 5                       test
well when i tried to test it the way we were testing it with custnum=444. When i tested it,it came up with the error
Conversion failed when converting the nvarchar value 'test' to data type int.
When i lookedat the database the only thing with the word test in it was that record.

When i took out the record with the name test in fk_custnum and tried to bring up 444 again it worked fine everything was filled in. However, with test in there it wouldnot do this.I event tried putting a different word in there called cat. As long as fk_custnum is all numbers it will autopopulate the rest of the fields. However, if you put a word or a letter in fk_custnum it will not work.

An i just noticed something else when i tried to type in a letter with a number in the customer number field. when i clicked
out of it to fill in another field it takes the letter away. like for example if i put a32 and click out of it, it makes it 32.

i think the database is correct because it says nvarchar(50) for fk_custNum. I think it might be with the ajax (based on it taking a letter out of my example a32). theres another file that goes with this called ajax.js. do you think it might be causeing it?

because this is all the ajax i got right now

Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript" src="ajax.js"></script>
  2.     <script type="text/javascript">
  3.  
  4. var ajax = new sack();
  5.     var currentClientID=false;
  6.     function getClientData()
  7.     {
  8.         var clientId = document.getElementById('clientID').value.replace(/[^0-9]/g,'');
  9.             currentClientID = clientId
  10.             ajax.requestFile = 'getClient.cfm?custnum='+clientId;    // Specifying which file to get
  11.             ajax.onCompletion = showClientData;    // Specify function that will be executed after file has been found
  12.             ajax.runAJAX();        // Execute AJAX function            
  13.  
  14.     }
  15.  
  16.     function showClientData()
  17.     {
  18.         var formObj = document.forms['page1'];    
  19.         eval(ajax.response);
  20.     }
  21.  
  22.  
  23.     function initFormEvents()
  24.     {
  25.         document.getElementById('clientID').onblur = getClientData;
  26.         document.getElementById('clientID').focus();
  27.     }
  28.  
  29.  
  30.     window.onload = initFormEvents;
  31.     </script>
do you want me to copy the script from ajax.js?

Thank you,
Rach
Aug 22 '08 #48

acoder
Expert Mod 15k+
P: 16,027
An i just noticed something else when i tried to type in a letter with a number in the customer number field. when i clicked
out of it to fill in another field it takes the letter away. like for example if i put a32 and click out of it, it makes it 32.
This is caused by this line:
Expand|Select|Wrap|Line Numbers
  1. var clientId = document.getElementById('clientID').value.replace(  /[^0-9]/g,'');
which you can change to:
Expand|Select|Wrap|Line Numbers
  1. var clientId = document.getElementById('clientID').value;
Aug 22 '08 #49

100+
P: 769
Hey Acoder,

Ok i got another problem with this (an think its because of what i added). But i went an added the drop down box. An now it wont let me type in a value into the input unless the value exists in the table (drop down).

heres what i got-heres the javascript changed
Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript">
  2.  
  3. var ajax = new sack();
  4.     var currentClientID=false;
  5.     function getClientData()
  6.     {
  7.         var clientId = document.getElementById('clientID').value;
  8.             currentClientID = clientId
  9.             ajax.requestFile = 'getClient.cfm?custnum='+clientId;    // Specifying which file to get
  10.             ajax.onCompletion = showClientData;    // Specify function that will be executed after file has been found
  11.             ajax.runAJAX();        // Execute AJAX function            
  12.  
  13.     }
  14.  
  15.     function showClientData()
  16.     {
  17.         var formObj = document.forms['page1'];    
  18.         eval(ajax.response);
  19.     }
  20.  
  21.  
  22.     function initFormEvents()
  23.     {
  24.         <!---document.getElementById('clientID').onblur = getClientData;
  25.         document.getElementById('clientID').focus();--->
  26.         document.getElementById("options").onchange = getClientData;
  27.     }
  28.  
  29.  
  30.     window.onload = initFormEvents;
  31.     </script>
an here is what my form looks like

Customer Number*:<input type="text" name="custnum" id="clientID" value="" ONKEYUP="autoComplete(this,this.form.options,'valu e',true)" onChange="validate(this.form.custnum,'Customer Number')"/>

<SELECT NAME="options" id="options"
onChange="this.form.custnum.value=this.options[this.selectedIndex].value;javascript:initFormEvents();">
<cfoutput query="getcustnum">
<option value="#fk_custNum#">#fk_custNum#</option>
</cfoutput>
</SELECT>

the drop down user a file called autocomplete.js

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.     }
Thank you :),
Rach
Aug 22 '08 #50

106 Replies

Post your reply

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