469,341 Members | 7,121 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,341 developers. It's quick & easy.

Auto fill form fields using coldfusion

769 512MB
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 17541
acoder
16,027 Expert Mod 8TB
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.
You need to pass a string to the query. At the moment you're passing an integer. Wrap the variable in quotes:
Expand|Select|Wrap|Line Numbers
  1. where fk_custNum='#url.custnum#'
Actually, now that this has been brought up, I should mention that to help prevent SQL injection attacks, you should be using cfqueryparam for any user inputted values passed into a query.

In addition to that, if you're using a stored query, use cfstoredproc/cfstoredprocparam instead of cfquery/cfqueryparam. Look those up - it'll be a better and safer way of coding.
Aug 23 '08 #51
bonneylake
769 512MB
Hey Acoder,

well first off sorry i was not able to respond to your reply till today. Yesterday everyone was sent home from work before we even got to are desk so i am really sorry i have not responded to this till now.

but i am still having trouble with it. Right now i am unable to type anything into the input box except if its a number that already exists in the drop down box,anything else it just makes it disappear right after you type it.but here is all the code that i got. i don't think this problem has to do with the getclient.cfm think its with the ajax..

here is the javascript that is on the same page as my form.

Expand|Select|Wrap|Line Numbers
  1. <SCRIPT LANGUAGE="JavaScript" SRC="autocomplete.js"></SCRIPT>
  2.     <script type="text/javascript" src="ajax.js"></script>
  3. <script type="text/javascript">
  4.  
  5. var ajax = new sack();
  6.     var currentClientID=false;
  7.     function getClientData()
  8.     {
  9.         var clientId = document.getElementById('clientID').value;
  10.             currentClientID = clientId
  11.             ajax.requestFile = 'getClient.cfm?custnum='+clientId;    // Specifying which file to get
  12.             ajax.onCompletion = showClientData;    // Specify function that will be executed after file has been found
  13.             ajax.runAJAX();        // Execute AJAX function            
  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.         document.getElementById("options").onchange = getClientData;
  29.     }
  30.  
  31.  
  32.     window.onload = initFormEvents;
  33.     </script>

here is the code on 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.     }
here is the code on ajax.js

Expand|Select|Wrap|Line Numbers
  1. function sack(file) {
  2.     this.xmlhttp = null;
  3.  
  4.     this.resetData = function() {
  5.         this.method = "POST";
  6.           this.queryStringSeparator = "?";
  7.         this.argumentSeparator = "&";
  8.         this.URLString = "";
  9.         this.encodeURIString = true;
  10.           this.execute = false;
  11.           this.element = null;
  12.         this.elementObj = null;
  13.         this.requestFile = file;
  14.         this.vars = new Object();
  15.         this.responseStatus = new Array(2);
  16.       };
  17.  
  18.     this.resetFunctions = function() {
  19.           this.onLoading = function() { };
  20.           this.onLoaded = function() { };
  21.           this.onInteractive = function() { };
  22.           this.onCompletion = function() { };
  23.           this.onError = function() { };
  24.         this.onFail = function() { };
  25.     };
  26.  
  27.     this.reset = function() {
  28.         this.resetFunctions();
  29.         this.resetData();
  30.     };
  31.  
  32.     this.createAJAX = function() {
  33.         try {
  34.             this.xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
  35.         } catch (e1) {
  36.             try {
  37.                 this.xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  38.             } catch (e2) {
  39.                 this.xmlhttp = null;
  40.             }
  41.         }
  42.  
  43.         if (! this.xmlhttp) {
  44.             if (typeof XMLHttpRequest != "undefined") {
  45.                 this.xmlhttp = new XMLHttpRequest();
  46.             } else {
  47.                 this.failed = true;
  48.             }
  49.         }
  50.     };
  51.  
  52.     this.setVar = function(name, value){
  53.         this.vars[name] = Array(value, false);
  54.     };
  55.  
  56.     this.encVar = function(name, value, returnvars) {
  57.         if (true == returnvars) {
  58.             return Array(encodeURIComponent(name), encodeURIComponent(value));
  59.         } else {
  60.             this.vars[encodeURIComponent(name)] = Array(encodeURIComponent(value), true);
  61.         }
  62.     }
  63.  
  64.     this.processURLString = function(string, encode) {
  65.         encoded = encodeURIComponent(this.argumentSeparator);
  66.         regexp = new RegExp(this.argumentSeparator + "|" + encoded);
  67.         varArray = string.split(regexp);
  68.         for (i = 0; i < varArray.length; i++){
  69.             urlVars = varArray[i].split("=");
  70.             if (true == encode){
  71.                 this.encVar(urlVars[0], urlVars[1]);
  72.             } else {
  73.                 this.setVar(urlVars[0], urlVars[1]);
  74.             }
  75.         }
  76.     }
  77.  
  78.     this.createURLString = function(urlstring) {
  79.         if (this.encodeURIString && this.URLString.length) {
  80.             this.processURLString(this.URLString, true);
  81.         }
  82.  
  83.         if (urlstring) {
  84.             if (this.URLString.length) {
  85.                 this.URLString += this.argumentSeparator + urlstring;
  86.             } else {
  87.                 this.URLString = urlstring;
  88.             }
  89.         }
  90.  
  91.         // prevents caching of URLString
  92.         this.setVar("rndval", new Date().getTime());
  93.  
  94.         urlstringtemp = new Array();
  95.         for (key in this.vars) {
  96.             if (false == this.vars[key][1] && true == this.encodeURIString) {
  97.                 encoded = this.encVar(key, this.vars[key][0], true);
  98.                 delete this.vars[key];
  99.                 this.vars[encoded[0]] = Array(encoded[1], true);
  100.                 key = encoded[0];
  101.             }
  102.  
  103.             urlstringtemp[urlstringtemp.length] = key + "=" + this.vars[key][0];
  104.         }
  105.         if (urlstring){
  106.             this.URLString += this.argumentSeparator + urlstringtemp.join(this.argumentSeparator);
  107.         } else {
  108.             this.URLString += urlstringtemp.join(this.argumentSeparator);
  109.         }
  110.     }
  111.  
  112.     this.runResponse = function() {
  113.         eval(this.response);
  114.     }
  115.  
  116.     this.runAJAX = function(urlstring) {
  117.         if (this.failed) {
  118.             this.onFail();
  119.         } else {
  120.             this.createURLString(urlstring);
  121.             if (this.element) {
  122.                 this.elementObj = document.getElementById(this.element);
  123.             }
  124.             if (this.xmlhttp) {
  125.                 var self = this;
  126.                 if (this.method == "GET") {
  127.                     totalurlstring = this.requestFile + this.queryStringSeparator + this.URLString;
  128.                     this.xmlhttp.open(this.method, totalurlstring, true);
  129.                 } else {
  130.                     this.xmlhttp.open(this.method, this.requestFile, true);
  131.                     try {
  132.                         this.xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded")
  133.                     } catch (e) { }
  134.                 }
  135.  
  136.                 this.xmlhttp.onreadystatechange = function() {
  137.                     switch (self.xmlhttp.readyState) {
  138.                         case 1:
  139.                             self.onLoading();
  140.                             break;
  141.                         case 2:
  142.                             self.onLoaded();
  143.                             break;
  144.  
  145.                         case 3:
  146.                             self.onInteractive();
  147.                             break;
  148.                         case 4:
  149.                             self.response = self.xmlhttp.responseText;
  150.                             self.responseXML = self.xmlhttp.responseXML;
  151.                             self.responseStatus[0] = self.xmlhttp.status;
  152.                             self.responseStatus[1] = self.xmlhttp.statusText;
  153.  
  154.                             if (self.execute) {
  155.                                 self.runResponse();
  156.                             }
  157.  
  158.                             if (self.elementObj) {
  159.                                 elemNodeName = self.elementObj.nodeName;
  160.                                 elemNodeName.toLowerCase();
  161.                                 if (elemNodeName == "input"
  162.                                 || elemNodeName == "select"
  163.                                 || elemNodeName == "option"
  164.                                 || elemNodeName == "textarea") {
  165.                                     self.elementObj.value = self.response;
  166.                                 } else {
  167.                                     self.elementObj.innerHTML = self.response;
  168.                                 }
  169.                             }
  170.                             if (self.responseStatus[0] == "200") {
  171.                                 self.onCompletion();
  172.                             } else {
  173.                                 self.onError();
  174.                             }
  175.  
  176.                             self.URLString = "";
  177.                             break;
  178.                     }
  179.                 };
  180.  
  181.                 this.xmlhttp.send(this.URLString);
  182.             }
  183.         }
  184.     };
  185.  
  186.     this.reset();
  187.     this.createAJAX();
  188. }
an here is what the input field for customer number and the drop down box next to it looks like

Expand|Select|Wrap|Line Numbers
  1. Customer Number*:<input type="text" name="custnum" id="clientID" value=""  ONKEYUP="autoComplete(this,this.form.options,'value',true)" onChange="validate(this.form.custnum,'Customer Number')"/>
  2. <SELECT NAME="options" id="options"
  3. onChange="this.form.custnum.value=this.options[this.selectedIndex].value;javascript:initFormEvents();">
  4. <cfoutput query="getcustnum">
  5. <option value="#fk_custNum#">#fk_custNum#</option>
  6. </cfoutput>
  7. </SELECT>
but thank you for all the help you have given me an again so sorry i didn't get to respond to this sooner.


Thank you,
Rach
Aug 26 '08 #52
acoder
16,027 Expert Mod 8TB
In your autoComplete function call, you're setting the fourth parameter (forceMatch) to true. Change it to false.
Aug 26 '08 #53
bonneylake
769 512MB
Hey Acoder

well when i tried to do it this way

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=false; break;
  6.         }
  7.     }
it worked the exact same way. but when i did it this way
Expand|Select|Wrap|Line Numbers
  1. function autoComplete (field, select, property, forcematch) {
  2.     var found = true;
  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.     }
it worked but then when i was done typing i got the error options[...] is null or not an object. Did they both need to be false false or both need to be true true or am i missing something?

Thank you,
Rach
Aug 26 '08 #54
acoder
16,027 Expert Mod 8TB
No, not the actual function. That works fine. I meant here:
Expand|Select|Wrap|Line Numbers
  1. Customer Number*:<input type="text" name="custnum" id="clientID" value=""  ONKEYUP="autoComplete(this,this.form.options,'value',true)" onChange="validate(this.form.custnum,'Customer Number')"/>
which needs to change to
Expand|Select|Wrap|Line Numbers
  1. Customer Number*:<input type="text" name="custnum" id="clientID" value=""  ONKEYUP="autoComplete(this,this.form.options,'value',false)" onChange="validate(this.form.custnum,'Customer Number')"/>
Aug 26 '08 #55
bonneylake
769 512MB
Hey Acoder,

that works till i try to click a new field an then i get the error object expected on 170 but only thing on 170 is </td> which i know can't be right. here is it updated

Expand|Select|Wrap|Line Numbers
  1. Customer Number*:</td><td><input type="text" name="custnum" id="clientID" value=""  ONKEYUP="autoComplete(this,this.form.options,'value',false)" onChange="validate(this.form.custnum,'Customer Number')"/>
Thank you,
Rach
Aug 26 '08 #56
acoder
16,027 Expert Mod 8TB
That must be caused by the validate() function. I think we're going back to the realms of JavaScript. If it can't be solved within a post or two, I suggest you post a new thread in the JavaScript forum. It may be that I end up helping you there anyway, but I like to keep things relevant to each forum :)
Aug 26 '08 #57
bonneylake
769 512MB
Hey Acoder,

well i can understand trying to keep everything organized :). an i know this is not a question that will be answered in one or 2 post cause still got another question after i figure out this part. But all post my question in the Javascript section. But still wanted to thank you for all the help you have given me, you truly been a life saver :)

Thank you again :),
Rach
Aug 26 '08 #58
acoder
16,027 Expert Mod 8TB
No problem. I think there's still one or two loose ends to tie up on the server-side, so I don't think this thread is over yet ;)
Aug 27 '08 #59
bonneylake
769 512MB
No problem. I think there's still one or two loose ends to tie up on the server-side, so I don't think this thread is over yet ;)
Hey Acoder,

yep still a few things left to figure out. Well i understand changing the name from totalAttachments to uploads but i don't understand the comma-delimited string. Here is what i got

Expand|Select|Wrap|Line Numbers
  1. <cfif structKeyExists(FORM, "uploads")>
  2.      <cfset currentDirectory = GetDirectoryFromPath(GetTemplatePath()) & "uploaded">
  3.      <cfparam name="FORM.uploads" default="0">
  4.      <cfloop from="1" to="#form.uploads#" index="counter">
  5.       <cfset currentDescription = form["description" & counter]>
  6.       <!---verify the form field exists --->
  7.      <cfif structKeyExists(FORM, "attachment"& counter)>
  8.           <!--- try and upload it ...--->
  9.           <cffile action="upload" fileField="form.attachment#counter#" destination="C:\Inetpub\Development\WWWRoot\RachelB\footprints\form\attachments\" nameconflict="MAKEUNIQUE">
  10.           <cfset filename = cffile.ClientFileName & "_" & form.id & "_" & counter & "." & cffile.ClientFileExt>
  11.           <CFFILE ACTION="RENAME" SOURCE="C:\Inetpub\Development\WWWRoot\RachelB\footprints\form\attachments\#CFFILE.ServerFile#" destination="C:\Inetpub\Development\WWWRoot\RachelB\footprints\form\attachments\#filename#">
  12.               <cfquery name="attachment" datasource="CustomerSupport">
  13.     exec usp_CS_Insertattachments
  14. '#Form.ID#','#evaluate(serialnum)#','#currentDescription#','#filename#','#Form.fk_addedBy#'
  15. </cfquery>
  16.      </cfif>
  17.      </cfloop>
  18. </cfif>
  19.  
Thank you,
Rach
Aug 27 '08 #60
acoder
16,027 Expert Mod 8TB
I moved your earlier post to upload multiple files like gmail problem since it is more relevant to that thread.
Aug 27 '08 #61
bonneylake
769 512MB
Hey Acoder,

just when i get it done i had to mess with it :(. well basically i deleted all the entrys in the contact table an now it wont autopopulate at all. Although the drop down box is being updated as i add new entrys. when i go to click insert it wont insert nothing. Any suggestions on what i could do to make it autopopulate again?


Thank you,
Rach
Sep 5 '08 #62
acoder
16,027 Expert Mod 8TB
Have you got an insert page that you have? If you've got no data, then the auto-fill won't work.
Sep 5 '08 #63
bonneylake
769 512MB
Have you got an insert page that you have? If you've got no data, then the auto-fill won't work.
Hey Acoder,

yes i have information in the table. i put new information into the table after i took the old information out. Took the old information because it was for testing purposes an almost done with the form so wanted to make sure there was not as many empty entrys. but i added an entry called test in there an i been trying to autopopulate using that. i went an did the getClient.cfm?custnum=test an it works correctly. it is even filling in the drop down box correctly. but it just wont autofill the form an when i try to i get the error about undetermined string constant.

Thank you,
Rach
Sep 5 '08 #64
acoder
16,027 Expert Mod 8TB
Try the Coldfusion page without Ajax and see the source code in the browser for what it produces. What's the output?
Sep 5 '08 #65
bonneylake
769 512MB
Try the Coldfusion page without Ajax and see the source code in the browser for what it produces. What's the output?
Hey Acoder,

i commented out all of the ajax that is suppose to be used with the autofill and well this is what the form looks from the source page.

Expand|Select|Wrap|Line Numbers
  1. Customer Number*:<input type="text" name="custnum" id="clientID" value=""  />
  2. <SELECT NAME="customer" id="options"
  3. >
  4. <option value="" selected></option>
  5.  
  6. <option value="test">test</option>
  7.  
  8. </SELECT>
  9.  
  10. <input type="button" class="custnum" name="insert" value="Insert Contact" 
  11.   >
  12.  
an test is the entry i added back into the table.

Thank you,
Rachel
Sep 5 '08 #66
acoder
16,027 Expert Mod 8TB
No, I meant getClient.cfm. Sorry, I should've made that clear.
Sep 5 '08 #67
bonneylake
769 512MB
No, I meant getClient.cfm. Sorry, I should've made that clear.
Hey Acoder,

here is what the source code looks like for the getClient.cfm page when i did getClient.cfm?custnum=test


Expand|Select|Wrap|Line Numbers
  1.       formObj.custnum.value = "test";
  2.       formObj.cust_company.value = "test";
  3.       formObj.fname.value = "test";
  4.       formObj.lname.value = "test";
  5.       formObj.add1.value = "test";
  6.       formObj.city.value = "test";
  7.       formObj.state.value = "test";
  8.       formObj.zip.value = "test";
  9.       formObj.email.value = "test";
  10.       formObj.pri_phone.value = "test";
  11.       formObj.sec_phone.value = "test";
  12.       formObj.notes.value = "This is a test
  13. ";
an here is what the browser looked like when i did
etClient.cfm?custnum=test

Expand|Select|Wrap|Line Numbers
  1. formObj.custnum.value = "test"; 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 = "This is a test ";
Thank you :),
Rach
Sep 5 '08 #68
acoder
16,027 Expert Mod 8TB
The problem is lines 12/13. Can you see that the string doesn't finish on that line, but goes onto the next line. This is the cause of non-terminated string error on the client-side. To solve it, you need to replace all newline characters with "\n" so that it can be recognised by JavaScript. Alternatively (and this is the better solution), just return a string separated by a unique character which can be split on the client-side.
Sep 5 '08 #69
bonneylake
769 512MB
The problem is lines 12/13. Can you see that the string doesn't finish on that line, but goes onto the next line. This is the cause of non-terminated string error on the client-side. To solve it, you need to replace all newline characters with "\n" so that it can be recognised by JavaScript. Alternatively (and this is the better solution), just return a string separated by a unique character which can be split on the client-side.
Hey Acoder,

Well you other solution sounds more promising and i was wondering how would i do it? would i do something like this


Expand|Select|Wrap|Line Numbers
  1.       formObj.custnum.value = "test"+
  2.       formObj.cust_company.value = "test"+
  3.       formObj.fname.value = "test"+
  4.       formObj.lname.value = "test"+
  5.       formObj.add1.value = "test"+
  6.       formObj.city.value = "test"+
  7.       formObj.state.value = "test"+
  8.       formObj.zip.value = "test"+
  9.       formObj.email.value = "test"+
  10.       formObj.pri_phone.value = "test"+
  11.       formObj.sec_phone.value = "test"+
  12.       formObj.notes.value = "This is a test"+
Thank you,
Rach
Sep 5 '08 #70
acoder
16,027 Expert Mod 8TB
No, it'd be something like:
Expand|Select|Wrap|Line Numbers
  1. test;test;test;...
generated by Coldfusion, then on the client-side, you don't use eval. You split the responseText and use these JavaScript statements to set the fields. Of course, that's one possibility. Others are XML and JSON.
Sep 5 '08 #71
bonneylake
769 512MB
No, it'd be something like:
Expand|Select|Wrap|Line Numbers
  1. test;test;test;...
generated by Coldfusion, then on the client-side, you don't use eval. You split the responseText and use these JavaScript statements to set the fields. Of course, that's one possibility. Others are XML and JSON.
Hey Acoder

so you don't do anything to the coldfusion as i understand
an then take out the eval(ajax.response); . Then the rest i have never done before so i am a bit baffled on how to do the responseText part. Do you know of a tutorial of forum that could explain how to do this because i have no clue how to begin doing that.

Thank you,
Rach
Sep 5 '08 #72
acoder
16,027 Expert Mod 8TB
You do need to make changes to the Coldfusion code. The formObj... lines in the cfquery would be replaced by just the values from the query, e.g.
Expand|Select|Wrap|Line Numbers
  1. <cfoutput...>
  2. #custnum#;#custcompany#;#fname#;...
For the cfelse part, you could just return nothing which you can check for in the JavaScript code.

I forgot that you're using the Sack library which means that ajax.response is what you need, not responseText. In your showClientData() function, instead of eval(ajax.response), set ajax.response to a variable to split using the split() method. Use the array to loop over the resulting array and use these JavaScript statements that you had on the Coldfusion side to set the text box values.

Note that ";" could be a poor choice for a delimiter. If you can be sure that no-one would ever input ; in any of the fields in the database, then you can use it, otherwise choose something else.

For some simple tutorials, check out the links in Off-site Links (JavaScript forum sticky).

See what you can come up with and if you get stuck, this thread continues...
Sep 6 '08 #73
bonneylake
769 512MB
Hey Acoder,

Well i tried to come up with something but i know i am missing a few things

Heres what i did to the coldfusion side

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.       #custnum#,
  10.       #cust_company#,
  11.       #fname#,
  12.       #lname#,
  13.       #add1#,
  14.       #city#,
  15.       #state#,
  16.       #zip#,
  17.       #email#,
  18.       #pri_phone#,
  19.       #sec_phone#,
  20.       #notes#
  21.        </cfoutput>
  22.       <cfelse>
  23.       </cfif>
an here is what i came up for the split
Expand|Select|Wrap|Line Numbers
  1.     function showClientData()
  2.     {
  3.         var formObj = document.forms['page1'];
  4.         ajax.response(formObj.split(" ")
  5.     }
the biggest part i am baffled by is this line

Expand|Select|Wrap|Line Numbers
  1.  Use the array to loop over the resulting array and use these JavaScript statements that you had on the Coldfusion side to set the text box values.
i am not sure what part needs to be in the loop. i am thinking the ajax.response. an then i am not sure what type of loop it needs to be used.

Thank you,
Rach
Sep 7 '08 #74
acoder
16,027 Expert Mod 8TB
You should probably avoid the line breaks to make it easier to split:
Expand|Select|Wrap|Line Numbers
  1. <cfoutput query="customerd">#custnum#,#cust_company#,#fname#,#lname#,#add1#,...</cfoutput>
  2.       <cfelse></cfif>
On the client-side, you need to split the ajax.response object:
Expand|Select|Wrap|Line Numbers
  1. var resp = ajax.response.split(",");
the biggest part i am baffled by is this line
Expand|Select|Wrap|Line Numbers
  1.  Use the array to loop over the resulting array and use these JavaScript statements that you had on the Coldfusion side to set the text box values.
split() returns an array of strings. Since you're only going to return one record, forget about the loop. Just take those earlier JavaScript statements that were in your Coldfusion code (in the cfoutput that you just changed) and put them here. Check first for it being empty:
Expand|Select|Wrap|Line Numbers
  1. if (ajax.response == "") { // you may want to trim here just in case
  2.     formObj.custnum.value = "";
  3.     formObj.custcompany.value = "";
  4.     // and so on...
  5. } else {
  6.     var resp = ajax.response.split(",");
  7.     formObj.custnum.value = resp[0];
  8.     formObj.custcompany.value = resp[1];
  9.     // and so on...
  10. }
Note that this assumes that the data will not have a comma.
Sep 8 '08 #75
bonneylake
769 512MB
Hey Acoder,

Ok well i got one minor thing wrong with it. For some reason when i autofill it. it takes the customer number value away, like once you click autofill it is gone.An if i click the insert contact twice the second time it goes to autofill i get undefined in all the columns. any suggestions

heres the javascript
Expand|Select|Wrap|Line Numbers
  1. function showClientData()
  2.     {
  3.       var formObj = document.forms['page1'];
  4.         var resp = ajax.response.split(",");
  5.  
  6.       if (ajax.response == "") { // you may want to trim here just in case
  7.           formObj.custnum.value = "";
  8.           formObj.cust_company.value = "";
  9.           formObj.fname.value = "";
  10.           formObj.lname.value = "";
  11.           formObj.add1.value = "";
  12.           formObj.city.value = "";
  13.           formObj.state.value = "";
  14.           formObj.zip.value = "";
  15.           formObj.email.value = "";
  16.           formObj.pri_phone.value = "";
  17.           formObj.sec_phone.value = "";
  18.           formObj.notes.value = "";
  19.  
  20.       } else {
  21.           var resp = ajax.response.split(",");
  22.           formObj.custnum.value = resp[0];
  23.           formObj.cust_company.value = resp[1];
  24.           formObj.fname.value = resp[2];
  25.           formObj.lname.value = resp[3];
  26.           formObj.add1.value = resp[4];
  27.           formObj.city.value = resp[5];
  28.           formObj.state.value = resp[6];
  29.           formObj.zip.value = resp[7];
  30.           formObj.email.value = resp[8];
  31.           formObj.pri_phone.value = resp[9];
  32.           formObj.sec_phone.value = resp[10];
  33.           formObj.notes.value = resp[11];
  34.       }
  35.     }    
an heres the coldfusion

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">     #custnum#,#cust_company#,#fname#,#lname#,#add1#,#city#,#state#,#zip#,#email#,#pri_phone#,#sec_phone#,#notes#
  9.        </cfoutput><cfelse></cfif>
Thank you again for all the help :),
Rach
Sep 8 '08 #76
acoder
16,027 Expert Mod 8TB
That's caused by the space after <cfoutput ...> Either trim the spaces in the JavaScript or remove it in the Coldfusion code.
Sep 8 '08 #77
bonneylake
769 512MB
Hey Acoder,

I tried that, but that didn't seem to cure the problems. How would i trim the javascript? heres the coldfusion in case you want to see it. for some reason in when i copy if the cfoutput appears on its own line but in my code its cfoutput query and the rest.

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">#custnum#,#cust_company#,#fname#,#lname#,#add1#,#city#,#state#,#zip#,#
  9. email#,#pri_phone#,#sec_phone#,#notes#</cfoutput><cfelse></cfif>
Thank you,
Rach
Sep 8 '08 #78
acoder
16,027 Expert Mod 8TB
If the customer number returned from Coldfusion is always the same as the one input, just remove it from the Coldfusion and the JavaScript, so it's not reset.
Sep 8 '08 #79
bonneylake
769 512MB
Hey Acoder,

that worked, but is there anyway to fix the undefined problem? because if i click the button an nothing is selected it says undefined. anyway to fix this?

Thank you for all the help :),
Rach
Sep 8 '08 #80
acoder
16,027 Expert Mod 8TB
You mean when nothing is selected in the drop down?
Sep 8 '08 #81
bonneylake
769 512MB
You mean when nothing is selected in the drop down?
yep when nothing is typed in the customer number or selected in the drop down box. would like to keep it blank then it say undefined an confuse the user.

Thank you :),
Rach
Sep 8 '08 #82
acoder
16,027 Expert Mod 8TB
It would be best to avoid making an Ajax request when there's no input by adding some simple validation. In any case, the Coldfusion should not return anything when no input is specified.
Sep 8 '08 #83
bonneylake
769 512MB
It would be best to avoid making an Ajax request when there's no input by adding some simple validation. In any case, the Coldfusion should not return anything when no input is specified.
hey acoder,

so if i do click on the insert button it should be leaving all the fields blank right now instead of putting in each field undefined, right? But what type validation should i add to it?.

Thank you.
Rach
Sep 8 '08 #84
acoder
16,027 Expert Mod 8TB
The validation you need on the client-side is to check that it's not empty before you call getClient.cfm. You should also test the Coldfusion.
Sep 8 '08 #85
bonneylake
769 512MB
The validation you need on the client-side is to check that it's not empty before you call getClient.cfm. You should also test the Coldfusion.
Hey Acoder,

checked the coldfusion and worked correctly for doing the customer number test. An also tried a number that no longer existed in the table an it left the page blank so its working correctly.

but how would i go about not calling the getClient.cfm if the customer field is left blank? could i do something as simple as this

Expand|Select|Wrap|Line Numbers
  1.  if(page1.customer.value== "")
  2.  {
  3.   }else{
  4. var ajax = new sack();
  5.     var currentClientID=false;
  6.     function getClientData()
  7.     {
  8.         var clientId = document.getElementById('clientID').value;
  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.         var resp = ajax.response.split(",");
  20.  
  21.       if (ajax.response == "") { // you may want to trim here just in case
  22.           formObj.cust_company.value = "";
  23.           formObj.fname.value = "";
  24.           formObj.lname.value = "";
  25.           formObj.add1.value = "";
  26.           formObj.city.value = "";
  27.           formObj.state.value = "";
  28.           formObj.zip.value = "";
  29.           formObj.email.value = "";
  30.           formObj.pri_phone.value = "";
  31.           formObj.sec_phone.value = "";
  32.           formObj.notes.value = "";
  33.  
  34.       } else {
  35.           var resp = ajax.response.split(",");
  36.           formObj.cust_company.value = resp[1];
  37.           formObj.fname.value = resp[2];
  38.           formObj.lname.value = resp[3];
  39.           formObj.add1.value = resp[4];
  40.           formObj.city.value = resp[5];
  41.           formObj.state.value = resp[6];
  42.           formObj.zip.value = resp[7];
  43.           formObj.email.value = resp[8];
  44.           formObj.pri_phone.value = resp[9];
  45.           formObj.sec_phone.value = resp[10];
  46.           formObj.notes.value = resp[11];
  47.       }
  48.     }
  49. }
Thank you,
Rach
Sep 8 '08 #86
acoder
16,027 Expert Mod 8TB
It is simple, but is only required in getClientData():
Expand|Select|Wrap|Line Numbers
  1. function getClientData()
  2.     {
  3.         var clientId = document.getElementById('clientID').value;
  4.         if (clientId != "") {
  5.             // make Ajax call...
  6.  
Sep 8 '08 #87
bonneylake
769 512MB
Hey Acoder,

Yay it works. THANK YOU so much for all the help!!! you have no idea how much i appreciate all the help you have given me ! Thank you, Thank you!!!

Thank you again, your awesome :),
Rach
Sep 8 '08 #88
acoder
16,027 Expert Mod 8TB
You're welcome :) Glad to help.
Sep 8 '08 #89
bonneylake
769 512MB
Hey Acoder,

i was afraid it was a coldfusion problem. The weird thing that is happening with this is when i am inserting information into the table i have noticed these squares in front of the fields i add an its only for those 3 fields mentioned.But anyway this information for the contacts gets insert into 2 tables one called ticketMaster and the other called contacts. When it goes into contacts it inserts correctly an does not put any spaces in the fields. But when it goes into ticketMaster the 3 fields always seem to have space in them.

ok i just did a test on it (tested by inserting new records) an here is what i am getting

on the cticketpage1.cfm page
when i insert the first customer in the contacts it looks fine an in the ticketMaster it looks fine except in the customer_notes where it puts 2 squares in front of it although i made sure before inserting that it had no spaces an on the form instead it appears to have no spaces.

when i get to the second page an i click update (i have a part in my form that allows the users to update information). It then puts the spaces in front of customer_number, city and notes.this also happens when i click submit at the bottom of the page because they resubmit the information when they submit the form.

here is what is on the page when i first submit the form for the first time

Code: ( text )

Expand|Select|Wrap|Line Numbers
  1.   <!---Inserts record into ticketmaster table--->
  2.       <cfquery name="insertticketmaster" datasource="CustomerSupport">
  3.           exec usp_CS_InsertticketMaster '#Form.title#','#Form.priority#','#Form.status#','  #Form.submitted_by#','#Form.last_edited_by#',
  4.           '#Form.clientID#','#Form.compname#','#Form.fname#'  ,
  5.         '#Form.lname#','#Form.address#','#Form.city#','#Fo  rm.state#','#Form.zip#','#Form.email#','#Form.prip  hone#','#Form.secphone#','
  6.           #Form.custnotes#','#Form.costcenterid#','#Form.htp  p#'
  7.       </cfquery>
  8.       <!---gets the id for ticketmaster an for all of the second part of form.--->
  9.       <cfset pkID=#insertticketmaster.ID#>
  10.       <!---inserts/updates record into contacts table. if new inserts if not new will update old record.--->
  11.       <cfquery name="insertcontacts" datasource="CustomerSupport">
  12.       exec usp_CS_UpdateInsertcontacts  '#Form.clientID#','#Form.compname#','#Form.fname#'  , '#Form.lname#','#Form.address#','#Form.city#','#Fo  rm.state#','#Form.zip#','#Form.email#','#Form.prip  hone#','#Form.secphone#','#Form.custnotes#'
  13.       </cfquery>


where is what happens when i update the form
Code: ( text )


Expand|Select|Wrap|Line Numbers
  1.       <!---Updates TicketMaster Table--->
  2.       <cfquery name="Update" datasource="CustomerSupport">
  3.       exec usp_CS_UpdateticketMaster '#Form.ID#','#Form.title#','#Form.priority#','#For  m.status#','#Form.last_edited_by#','
  4.          #Form.clientID#','#Form.compname#','#Form.fname#',  '#Form.lname#','#Form.add1#','
  5.           #Form.city#','#Form.state#','#Form.zip#','#Form.em  ail#','#Form.priphone#','#Form.secphone#','
  6.           #Form.notes#','#Form.cost_center#','#Form.htpp#'
  7.       </cfquery>
  8.       <!---Updates/Inserts Contacts table (should only update in this case unless they create a new customer number right here which they shouldn't)--->
  9.       <cfquery name="insertcontacts" datasource="CustomerSupport">
  10.       exec usp_CS_UpdateInsertcontacts  '#Form.clientID#','#Form.compname#','#Form.fname#'  , '#Form.lname#','#Form.add1#','#Form.city#','#Form.  state#','#Form.zip#','#Form.email#','#Form.priphon  e#','#Form.secphone#','#Form.notes#'
  11.       </cfquery>



here is what happens when i submit the entire form for the 2nd an final time
Code: ( text )

Expand|Select|Wrap|Line Numbers
  1.       <!---Inserts Data for General Information and Contact Information.--->
  2.       <cfquery name="Update" datasource="CustomerSupport">
  3.       exec usp_CS_UpdateticketMaster '#Form.ID#','#Form.title#','#Form.priority#','#For  m.status#','#Form.last_edited_by#','
  4.          #Form.clientID#','#Form.compname#','#Form.fname#',  '#Form.lname#','#Form.address#','
  5.           #Form.city#','#Form.state#','#Form.zip#','#Form.em  ail#','#Form.priphone#','#Form.secphone#','
  6.           #Form.custnotes#','#Form.cost_center#','#Form.htpp  #'
  7.       </cfquery>
  8.       <!---Updates/Inserts Contacts table (should only update in this case unless they create a new customer number right here which they shouldn't)--->
  9.       <cfquery name="insertcontacts" datasource="CustomerSupport">
  10.       exec usp_CS_UpdateInsertcontacts  '#Form.clientID#','#Form.compname#','#Form.fname#'  , '#Form.lname#','#Form.address#','#Form.city#','#Fo  rm.state#','#Form.zip#','#Form.email#','#Form.prip  hone#','#Form.secphone#','#Form.custnotes#'
  11.       </cfquery>
  12.  

thats the only thing the 3 of them all have in common, the only thing different is that for the update it has a javascript script, but i don't think that could be it.But could you explain what you mean by this

I do notice that you have spaces/line breaks for the afore-mentioned three fields within the quotes.
Any ideas?

Thank you for the help,
Rach
Sep 18 '08 #90
acoder
16,027 Expert Mod 8TB
If you look at the queries, look for the clientID, city and notes. You will notice that the quotes begin on one line and end on the next. This is what's causing the problem. You will also notice that no other field has line breaks.

Note: instead of duplicating code like this, it might be an idea to put it in one place and call it wherever required.
Sep 18 '08 #91
bonneylake
769 512MB
If you look at the queries, look for the clientID, city and notes. You will notice that the quotes begin on one line and end on the next. This is what's causing the problem. You will also notice that no other field has line breaks.

Note: instead of duplicating code like this, it might be an idea to put it in one place and call it wherever required.
Hey Acoder,

That was the problem, which wow can't believe that small problem caused that ! THANK YOU, THANK YOU!!! I have just 1minor questions left to ask. Well on the customer notes it still has space behind it an it appears in the database is there anyway to make it not have the space behind it, an is it a huge deal for it to have space behind it?

Thank you,
Rach
Sep 18 '08 #92
acoder
16,027 Expert Mod 8TB
You mean at the end? Check that the quotes only go around the variable and nothing else - no spaces, line breaks, etc.
Sep 18 '08 #93
bonneylake
769 512MB
Hey acoder,

i am definately stuck on this one. I got it to insert correctly the first time, but when i try to get it to update an do the final insert it don't work right. Here is what i have

first time
Expand|Select|Wrap|Line Numbers
  1. <!---Inserts Data for General Information and Contact Information.--->
  2. <cfquery name="Update" datasource="CustomerSupport">
  3. exec usp_CS_UpdateticketMaster '#Form.pk_ticketID#','#Form.title#','#Form.priority#','#Form.status#','#Form.last_edited_by#'
  4. ,'#Form.custnum#','#Form.compname#','#Form.fname#','#Form.lname#','#Form.address#'
  5. ,'#Form.city#','#Form.state#','#Form.zip#','#Form.email#','#Form.priphone#','#Form.secphone#'
  6. ,'#Form.custnotes#','#Form.cost_center#','#Form.htpp#'
  7. </cfquery>
  8.  
  9. <!---Updates/Inserts Contacts table (should only update in this case unless they create a new customer number right here which they shouldn't)--->
  10. <cfquery name="insertcontacts" datasource="CustomerSupport">
  11. exec usp_CS_UpdateInsertcontacts  '#Form.custnum#','#Form.compname#','#Form.fname#', '#Form.lname#','#Form.address#','#Form.city#','#Form.state#','#Form.zip#','#Form.email#','#Form.priphone#','#Form.secphone#',
  12. '#Form.custnotes#'
  13. </cfquery>
update
Expand|Select|Wrap|Line Numbers
  1. <!---Updates TicketMaster Table--->
  2. <cfquery name="Update" datasource="CustomerSupport">
  3. exec usp_CS_UpdateticketMaster '#Form.ID#','#Form.title#','#Form.priority#','#Form.status#','#Form.last_edited_by#'
  4. ,'#Form.custnum#','#Form.compname#','#Form.fname#','#Form.lname#','#Form.add1#'
  5. ,'#Form.city#','#Form.state#','#Form.zip#','#Form.email#','#Form.priphone#','#Form.secphone#','#Form.custnotes#','#Form.cost_center#'
  6. ,'#Form.htpp#'
  7. </cfquery>
  8.  
  9. <!---Updates/Inserts Contacts table (should only update in this case unless they create a new customer number right here which they shouldn't)--->
  10. <cfquery name="insertcontacts" datasource="CustomerSupport">
  11. exec usp_CS_UpdateInsertcontacts  '#Form.custnum#','#Form.compname#','#Form.fname#', '#Form.lname#','#Form.add1#','#Form.city#','#Form.state#','#Form.zip#','#Form.email#','#Form.priphone#','#Form.secphone#','#Form.custnotes#'
  12. </cfquery>

final submit
Expand|Select|Wrap|Line Numbers
  1. <!---Inserts Data for General Information and Contact Information.--->
  2. <cfquery name="Update" datasource="CustomerSupport">
  3. exec usp_CS_UpdateticketMaster '#Form.ID#','#Form.title#','#Form.priority#','#Form.status#','#Form.last_edited_by#'
  4. ,'#Form.custnum#','#Form.compname#','#Form.fname#','#Form.lname#','#Form.address#'
  5. ,'#Form.city#','#Form.state#','#Form.zip#','#Form.email#','#Form.priphone#','#Form.secphone#'
  6. ,'#Form.custnotes#','#Form.costcenterid#','#Form.htpp#'
  7. </cfquery>
  8.  
  9. <!---Updates/Inserts Contacts table (should only update in this case unless they create a new customer number right here which they shouldn't)--->
  10. <cfquery name="insertcontacts" datasource="CustomerSupport">
  11. exec usp_CS_UpdateInsertcontacts  '#Form.custnum#','#Form.compname#','#Form.fname#', '#Form.lname#','#Form.address#','#Form.city#','#Form.state#','#Form.zip#','#Form.email#','#Form.priphone#','#Form.secphone#'
  12. ,'#Form.custnotes#'
  13. </cfquery>
Thank you,
Rach
Sep 18 '08 #94
acoder
16,027 Expert Mod 8TB
When you say it doesn't work right, what happens? Are there any errors?
Sep 18 '08 #95
bonneylake
769 512MB
When you say it doesn't work right, what happens? Are there any errors?
Hey Acoder,

i think i know what it is, but not sure what to do about it. On the first page the cursor appears directly behind whatever you added in the notes. However when you get to the second page it appears underneath whatever you wrote. When i took that space out it didn't add it to the table for either the update or the final insert. So is there a way to make the curser appear behind the text added in a textarea field?

Thank you :),
Rach
Sep 19 '08 #96
bonneylake
769 512MB
Hey Acoder,

I figured out the problem to the notes. Turns out this is how i had it
Expand|Select|Wrap|Line Numbers
  1. <textarea maxlength='500' onkeyup='return ismaxlength(this)' onkeydown='return ismaxlength(this)'rows="4" cols="60" name="custnotes" id="notes">#Form.custnotes#
  2. </textarea>
this is how it needed to be

Expand|Select|Wrap|Line Numbers
  1. <textarea maxlength='500' onkeyup='return ismaxlength(this)' onkeydown='return ismaxlength(this)'rows="4" cols="60" name="custnotes" id="notes">#Form.custnotes#</textarea>
Crazy or what?

But i got two more question. Lately i have run into the problem where when i go to create a new ticket. Lets say i already have a value in the contact table called 22222. Anyway if i go to type the value of 22 in the field instead of the drop down box changing to blank (since 22 does not exist) it will still say 222222, is there anyway i can get it so that it will go blank in the drop down box if the field don't exist in the table?

Anthe last question i am not sure if this is possible but wanted to ask. If someone starts typing a number in the field it starts adding what it thinks i am guessing behind it an was wondering if there was anyway to still get the drop down box to populate but not add what it thinks i am typing in in the field box?

Thank you again for all the help :),
Rach
Sep 19 '08 #97
acoder
16,027 Expert Mod 8TB
I figured out the problem to the notes.
Crazy or what?
Those small nuances can make all the difference.

But i got two more question. Lately i have run into the problem where when i go to create a new ticket. Lets say i already have a value in the contact table called 22222. Anyway if i go to type the value of 22 in the field instead of the drop down box changing to blank (since 22 does not exist) it will still say 222222, is there anyway i can get it so that it will go blank in the drop down box if the field don't exist in the table?
So you want this to happen as soon as you start typing and not when you focus away from the field?

Anthe last question i am not sure if this is possible but wanted to ask. If someone starts typing a number in the field it starts adding what it thinks i am guessing behind it an was wondering if there was anyway to still get the drop down box to populate but not add what it thinks i am typing in in the field box?
Yes, this is possible. Just remove the call to the function/code which adds to the field.
Sep 19 '08 #98
bonneylake
769 512MB
Those small nuances can make all the difference.

So you want this to happen as soon as you start typing and not when you focus away from the field?

Yes, this is possible. Just remove the call to the function/code which adds to the field.
Hey Acoder,

Yes i would like this to happen when i am typing afraid there get confused other wise if they continue to see it as they type.

an which part do i remove? do i remove it out of the field itself

Expand|Select|Wrap|Line Numbers
  1. <input type="text" name="custnum" id="clientID" value=""  ONKEYUP="autoComplete(this,this.form.customer,'value',false)"/>
  2. <SELECT NAME="customer" id="options"
  3. onChange="this.form.custnum.value=this.options[this.selectedIndex].value;">
  4. <option value="" selected></option>
  5. <cfoutput query="getcustnum">
  6. <option value="#fk_custNum#">#fk_custNum#</option>
  7. </cfoutput>
  8. </SELECT>
or the javascript?

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;
  6.         if (clientId != "") {
  7.             currentClientID = clientId
  8.             ajax.requestFile = 'getClient.cfm?custnum='+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.  
  15.  
  16.     function showClientData()
  17.     {
  18.         var formObj = document.forms['page1'];
  19.         var resp = ajax.response.split(",");
  20.  
  21.       if (ajax.response == "") { // you may want to trim here just in case
  22.           formObj.cust_company.value = "";
  23.           formObj.fname.value = "";
  24.           formObj.lname.value = "";
  25.           formObj.add1.value = "";
  26.           formObj.city.value = "";
  27.           formObj.state.value = "";
  28.           formObj.zip.value = "";
  29.           formObj.email.value = "";
  30.           formObj.pri_phone.value = "";
  31.           formObj.sec_phone.value = "";
  32.           formObj.notes.value = "";
  33.  
  34.       } else {
  35.           var resp = ajax.response.split(",");
  36.           formObj.cust_company.value = resp[1];
  37.           formObj.fname.value = resp[2];
  38.           formObj.lname.value = resp[3];
  39.           formObj.add1.value = resp[4];
  40.           formObj.city.value = resp[5];
  41.           formObj.state.value = resp[6];
  42.           formObj.zip.value = resp[7];
  43.           formObj.email.value = resp[8];
  44.           formObj.pri_phone.value = resp[9];
  45.           formObj.sec_phone.value = resp[10];
  46.           formObj.notes.value = resp[11];
  47.       }
  48.     }
Thank you :),
Rach
Sep 19 '08 #99
acoder
16,027 Expert Mod 8TB
For the first question, you may have to change the autoComplete function. You could default to the first option to begin with.

I may have misunderstood the second question. If you meant that it appears below the field with the previous entries, then you can use 'autocomplete="off"' as an attribute for the field.
Sep 20 '08 #100

Post your reply

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

Similar topics

2 posts views Thread by John Scott | last post: by
1 post views Thread by mikeybe | last post: by
2 posts views Thread by Joanne Lewis | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
reply views Thread by Purva khokhar | last post: by
1 post views Thread by haryvincent176 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.