Auto fill form fields using coldfusion

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #61
    I moved your earlier post to upload multiple files like gmail problem since it is more relevant to that thread.

    Comment

    • bonneylake
      Contributor
      • Aug 2008
      • 769

      #62
      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

      Comment

      • acoder
        Recognized Expert MVP
        • Nov 2006
        • 16032

        #63
        Have you got an insert page that you have? If you've got no data, then the auto-fill won't work.

        Comment

        • bonneylake
          Contributor
          • Aug 2008
          • 769

          #64
          Originally posted by acoder
          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?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,
          Rach

          Comment

          • acoder
            Recognized Expert MVP
            • Nov 2006
            • 16032

            #65
            Try the Coldfusion page without Ajax and see the source code in the browser for what it produces. What's the output?

            Comment

            • bonneylake
              Contributor
              • Aug 2008
              • 769

              #66
              Originally posted by acoder
              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.

              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" 
                >
              an test is the entry i added back into the table.

              Thank you,
              Rachel

              Comment

              • acoder
                Recognized Expert MVP
                • Nov 2006
                • 16032

                #67
                No, I meant getClient.cfm. Sorry, I should've made that clear.

                Comment

                • bonneylake
                  Contributor
                  • Aug 2008
                  • 769

                  #68
                  Originally posted by acoder
                  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?c ustnum=test


                  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
                  ";
                  an here is what the browser looked like when i did
                  etClient.cfm?cu stnum=test

                  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 ";
                  Thank you :),
                  Rach

                  Comment

                  • acoder
                    Recognized Expert MVP
                    • Nov 2006
                    • 16032

                    #69
                    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

                    • bonneylake
                      Contributor
                      • Aug 2008
                      • 769

                      #70
                      Originally posted by acoder
                      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


                      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"+
                      Thank you,
                      Rach

                      Comment

                      • acoder
                        Recognized Expert MVP
                        • Nov 2006
                        • 16032

                        #71
                        No, it'd be something like:
                        Code:
                        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.

                        Comment

                        • bonneylake
                          Contributor
                          • Aug 2008
                          • 769

                          #72
                          Originally posted by acoder
                          No, it'd be something like:
                          Code:
                          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.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,
                          Rach

                          Comment

                          • acoder
                            Recognized Expert MVP
                            • Nov 2006
                            • 16032

                            #73
                            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

                            • bonneylake
                              Contributor
                              • Aug 2008
                              • 769

                              #74
                              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

                              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">
                                    #custnum#,
                                    #cust_company#,
                                    #fname#,
                                    #lname#,
                                    #add1#,
                                    #city#,
                                    #state#,
                                    #zip#,
                                    #email#,
                                    #pri_phone#,
                                    #sec_phone#,
                                    #notes#
                                     </cfoutput>
                                    <cfelse>
                                    </cfif>
                              an here is what i came up for the split
                              Code:
                              	function showClientData()
                              	{
                              		var formObj = document.forms['page1'];
                              		ajax.response(formObj.split(" ")
                              	}
                              the 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.
                              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

                              Comment

                              • acoder
                                Recognized Expert MVP
                                • Nov 2006
                                • 16032

                                #75
                                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]
                                Originally posted by bonneylake
                                the 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.
                                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:
                                [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

                                Working...