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.
Auto fill form fields using coldfusion
Collapse
X
-
Hey Acoder,
Ok here is what i got now, is this right?
Thank you :),Code:<cfif custnum NEQ "" AND custnum.recordcount IS NOT 0> <cfoutput query= "custnum"> formObj.custnum.value = "#custnum#"; formObj.compname.value = "#compname#"; formObj.fname.value = "#fname#"; formObj.lname.value = "#lname#"; formObj.address.value = "#address#"; formObj.city.value = "#city#"; formObj.state.value = "#state#"; formObj.zip.value = "#zip#"; formObj.email.value = "#email#"; formObj.priphone.value = "#priphone#"; formObj.secphone.value = "#secphone#"; formObj.custnotes.value = "#custnotes#"; </cfoutput> <cfelse> 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 = ""; </cfif>
RachComment
-
Acoder,
ok when i typed in 111 (which forgot i didn't have 111 in my database) i got this
however, when i typed in a number that is in my database i got thisCode: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 = "";
Code:Error Diagnostic Information Expression result cannot be converted to a string 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. 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
Thank you :),Code:<cfparam name="url.custnum" default=""> <cfquery name="custnum" datasource="CustomerSupport"> select * from dbo.tbl_CS_contacts where fk_custNum=#url.custnum# </cfquery> <cfif url.custnum NEQ "" AND custnum.recordcount IS NOT 0> <cfoutput query= "custnum"> formObj.custnum.value = "#custnum#"; formObj.compname.value = "#compname#"; formObj.fname.value = "#fname#"; formObj.lname.value = "#lname#"; formObj.address.value = "#address#"; formObj.city.value = "#city#"; formObj.state.value = "#state#"; formObj.zip.value = "#zip#"; formObj.email.value = "#email#"; formObj.priphone.value = "#priphone#"; formObj.secphone.value = "#secphone#"; formObj.custnotes.value = "#custnotes#"; </cfoutput> <cfelse> 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 = ""; </cfif>
RachComment
-
Acoder,
Ok i get the error
.Code:Error Diagnostic Information ODBC Error Code = 37000 (Syntax error or access violation) [Microsoft][ODBC SQL Server Driver][SQL Server]Incorrect syntax near '='. SQL = "select * from dbo.tbl_CS_contacts where fk_custNum=" Data Source = "CUSTOMERSUPPORT" 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?
Thank you,Code:<cfparam name="url.custnum" default=""> <cfquery name="customerd" datasource="CustomerSupport"> select * from dbo.tbl_CS_contacts where fk_custNum=#url.custnum# </cfquery> <cfif url.custnum NEQ "" AND customerd.recordcount IS NOT 0> <cfoutput query= "customerd"> formObj.custnum.value = "#custnum#"; formObj.compname.value = "#compname#"; formObj.fname.value = "#fname#"; formObj.lname.value = "#lname#"; formObj.address.value = "#address#"; formObj.city.value = "#city#"; formObj.state.value = "#state#"; formObj.zip.value = "#zip#"; formObj.email.value = "#email#"; formObj.priphone.value = "#priphone#"; formObj.secphone.value = "#secphone#"; formObj.custnotes.value = "#custnotes#"; </cfoutput> <cfelse> 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 = ""; </cfif>
RachComment
-
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)
an here is what all of getClient.cfm looks likeCode: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";
Whats next?Code:<cfparam name="url.custnum" default=""> <cfquery name="customerd" datasource="CustomerSupport"> select * from dbo.tbl_CS_contacts where fk_custNum=#url.custnum# </cfquery> <cfif url.custnum NEQ "" AND customerd.recordcount IS NOT 0> <cfoutput query="customerd"> formObj.custnum.value = "#custnum#"; formObj.cust_company.value = "#cust_company#"; formObj.fname.value = "#fname#"; formObj.lname.value = "#lname#"; formObj.add1.value = "#add1#"; formObj.city.value = "#city#"; formObj.state.value = "#state#"; formObj.zip.value = "#zip#"; formObj.email.value = "#email#"; formObj.pri_phone.value = "#pri_phone#"; formObj.sec_phone.value = "#sec_phone#"; formObj.notes.value = "#notes#"; </cfoutput> <cfelse> formObj.custnum.value = ""; formObj.cust_company.value = ""; formObj.fname.value = ""; formObj.lname.value = ""; formObj.add1.value = ""; formObj.city.value = ""; formObj.state.value = ""; formObj.zip.value = ""; formObj.email.value = ""; formObj.pri_phone.value = ""; formObj.sec_phone.value = ""; formObj.notes.value = ""; </cfif>
Thank you :),
RachComment
-
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
an was wondering after the ? what would i add? would i put #url.custnum#=" +clidentid;?Code:ajax.requestFile = 'getClient.cfm?getClientId='+clientId;
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
Code:var ajax = new sack(); var currentClientID=false; function getClientData() { var clientId = document.getElementById('clientID').value.replace(/[^0-9]/g,''); if(clientId.length==4 && clientId!=currentClientID){ currentClientID = clientId ajax.requestFile = 'getClient.cfm?getClientId='+clientId; // Specifying which file to get ajax.onCompletion = showClientData; // Specify function that will be executed after file has been found ajax.runAJAX(); // Execute AJAX function } } function showClientData() { var formObj = document.forms['clientForm']; eval(ajax.response); } function initFormEvents() { document.getElementById('clientID').onblur = getClientData; document.getElementById('clientID').focus(); } window.onload = initFormEvents;
Thank you for all the help you have given me i really do appreciate it :),
RachComment
-
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
an heres what my form looks likeCode:<script type="text/javascript"> var ajax = new sack(); var currentClientID=false; function getClientData() { var clientId = document.getElementById('clientID').value.replace(/[^0-9]/g,''); if(clientId.length==4 && clientId!=currentClientID){ currentClientID = clientId ajax.requestFile = 'getClient.cfm?custnum='+clientId; // Specifying which file to get ajax.onCompletion = showClientData; // Specify function that will be executed after file has been found ajax.runAJAX(); // Execute AJAX function } } function showClientData() { var formObj = document.forms['page1']; eval(ajax.response); } function initFormEvents() { document.getElementById('clientID').onblur = getClientData; document.getElementById('clientID').focus(); } window.onload = initFormEvents; </script>
Any suggestions? Thank you :)Code:<form name="page1" action="saveticket1.cfm" method="POST"> <input type="text" name="custnum" id="clientID" value="" /> <input type="text" name="compname" id="cust_company" value="" size="20"/> <input type="text" name="fname" id="fname" value="" size="20"/> <input type="text" name="lname" id="lname" value="" size="20"/> <input type="text" name="address" value="" id="add1" size="20"/> <input type="text" name="city" id="city" value="" size="20"/> <input type="text" name="state" id="state" value="" size="20"/> <input type="text" name="zip" id="zip" value="" size="20"/> <input type="text" name="email" id="email" value="" size="20"/> <input type="text" name="priphone" id="pri_phone"value="" size="20"/> <input type="text" name="secphone" id="sec_phone" value="" size="20"/> <textarea maxlength='500' onkeyup='return ismaxlength(this)' onkeydown='return ismaxlength(this)' rows="4" cols="60" name="custnotes" id="notes" value=""></textarea> <input type="submit" value="Submit" class="officalsubmit"/> </form>
RachComment
-
What's the length of the customer number that you're testing with? On line 8:
[code=javascript]if(clientId.len gth==4 && clientId!=curre ntClientID){[/code]if the clientId is less than 1000, it won't do anything. If you want any number then remove that condition.Comment
-
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
Thank you,Code:var ajax = new sack(); var currentClientID=false; function getClientData() { var clientId = document.getElementById('clientID').value.replace(/[^0-9]/g,''); currentClientID = clientId ajax.requestFile = 'getClient.cfm?custnum='+clientId; // Specifying which file to get ajax.onCompletion = showClientData; // Specify function that will be executed after file has been found ajax.runAJAX(); // Execute AJAX function } function showClientData() { var formObj = document.forms['page1']; eval(ajax.response); } function initFormEvents() { document.getElementById('clientID').onblur = getClientData; document.getElementById('clientID').focus(); } window.onload = initFormEvents;
RachComment
Comment