I moved your earlier post to upload multiple files like gmail problem since it is more relevant to that thread.
Auto fill form fields using coldfusion
Collapse
X
-
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,
RachComment
-
Hey Acoder,Originally posted by acoderHave you got an insert page that you have? If you've got no data, then the auto-fill won't work.
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?c ustnum=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,
RachComment
-
Hey Acoder,Originally posted by acoderTry the Coldfusion page without Ajax and see the source code in the browser for what it produces. What's the output?
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.
an test is the entry i added back into the table.Code:Customer Number*:<input type="text" name="custnum" id="clientID" value="" /> <SELECT NAME="customer" id="options" > <option value="" selected></option> <option value="test">test</option> </SELECT> <input type="button" class="custnum" name="insert" value="Insert Contact" >
Thank you,
RachelComment
-
Hey Acoder,Originally posted by acoderNo, I meant getClient.cfm. Sorry, I should've made that clear.
here is what the source code looks like for the getClient.cfm page when i did getClient.cfm?c ustnum=test
an here is what the browser looked like when i didCode: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 ";
etClient.cfm?cu stnum=test
Thank you :),Code: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 ";
RachComment
-
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.Comment
-
Hey Acoder,Originally posted by acoderThe 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.
Well you other solution sounds more promising and i was wondering how would i do it? would i do something like this
Thank you,Code: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"+
RachComment
-
No, it'd be something like:
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.Code:test;test;test;...
Comment
-
Hey AcoderOriginally posted by acoderNo, it'd be something like:
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.Code:test;test;test;...
so you don't do anything to the coldfusion as i understand
an then take out the eval(ajax.respo nse); . 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,
RachComment
-
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.
[code=cfm]<cfoutput...>
#custnum#;#cust company#;#fname #;...[/code]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.respo nse), 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...Comment
-
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
an here is what i came up for the splitCode:<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"> #custnum#, #cust_company#, #fname#, #lname#, #add1#, #city#, #state#, #zip#, #email#, #pri_phone#, #sec_phone#, #notes# </cfoutput> <cfelse> </cfif>
the biggest part i am baffled by is this lineCode:function showClientData() { var formObj = document.forms['page1']; ajax.response(formObj.split(" ") }
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.Code: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.
Thank you,
RachComment
-
You should probably avoid the line breaks to make it easier to split:
[code=cfm]<cfoutput query="customer d">#custnum#,#c ust_company#,#f name#,#lname#,# add1#,...</cfoutput>
<cfelse></cfif>[/CODE]On the client-side, you need to split the ajax.response object:
[code=javascript]var resp = ajax.response.s plit(",");[/code]
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:Originally posted by bonneylakethe biggest part i am baffled by is this line
Code: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.
[code=javascript]if (ajax.response == "") { // you may want to trim here just in case
formObj.custnum .value = "";
formObj.custcom pany.value = "";
// and so on...
} else {
var resp = ajax.response.s plit(",");
formObj.custnum .value = resp[0];
formObj.custcom pany.value = resp[1];
// and so on...
}[/code]Note that this assumes that the data will not have a comma.Comment
Comment