Autofill form fields, almost working

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

    #46
    OK, that's good to hear. You should also test the Coldfusion side of things when it doesn't seem to be working to see if it's giving the correct output.

    Comment

    • bonneylake
      Contributor
      • Aug 2008
      • 769

      #47
      Hey Acoder,

      The error came up today. An i did the test like you said an its getting the correct information. But today it finally told me what is wrong an it says it has a problem with the following line. the line is bolded. The error it gives me is undetermined string constant

      Code:
      	function showClientData()
      	{
      		var formObj = document.forms['page1'];	
      		[B]eval(ajax.response);[/B]
      	}
      Any ideas? here is what firefox told me

      Error: document.getEle mentById("inser t") has no properties
      Line: 66

      Error: unterminated string literal
      Line: 96, Column: 28
      Source Code:
      formObj.notes.v alue = "This is a test

      here is the javascript that appears on the form page (which is what is having a problem)

      Code:
      	<script type="text/javascript">
      
      var ajax = new sack();
      	var currentClientID=false;
      	function getClientData()
      	{
      		var clientId = document.getElementById('clientID').value;
      			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("insert").onclick = getClientData;
        
      		
      	
      	}
      	
      	
      	window.onload = initFormEvents;
      	</script>
      Thank you :),
      Rach

      Comment

      • acoder
        Recognized Expert MVP
        • Nov 2006
        • 16032

        #48
        This is caused by the Coldfusion-generated code where the string has not been terminated properly. Check the output. What does it show?

        PS. I think you could probably take this back to the Coldfusion thread.

        Comment

        • bonneylake
          Contributor
          • Aug 2008
          • 769

          #49
          Originally posted by acoder
          This is caused by the Coldfusion-generated code where the string has not been terminated properly. Check the output. What does it show?

          PS. I think you could probably take this back to the Coldfusion thread.
          Hey Acoder,

          i tried the getClient="" and it gave me the correct choice. The only thing i did to it was i took all the previously enter entrys out of the table an now wont work at all.

          an also it is stll updating the drop down. if i add a new one an then go back you will see the new one. its just not auto populating the form.

          Thank you,
          Rach

          Comment

          • acoder
            Recognized Expert MVP
            • Nov 2006
            • 16032

            #50
            As I mentioned in the other thread, if you've got no data, it can't populate with anything.

            Comment

            • bonneylake
              Contributor
              • Aug 2008
              • 769

              #51
              Hey Acoder,

              Well i got another question involving the same topic an hope you wouldn't mind answering it.

              I am working on now trying to redisplay information so that users can edit it. An well for some reason it is acting weird. when i pull up a ticket an you see all the contact information. When i go to submit it to go to the second page, when i get to the second page where i see the same exact information for some reason the customer number,city and notes fields will put space a little bit of space in front of the value. an the more editing i do to the same ticket the more space i am getting for those fields. The problem with that is every time that little bit of space is added it adds more contacts to my contacts table which i don't need. I have no clue whats causing this an was wondering if you had a suggestion?

              Thank you,
              Rach

              Comment

              • acoder
                Recognized Expert MVP
                • Nov 2006
                • 16032

                #52
                Have you made any changes to the code that you had in the two threads (this and the one in Coldfusion)? Post your latest relevant code.

                Comment

                • bonneylake
                  Contributor
                  • Aug 2008
                  • 769

                  #53
                  Originally posted by acoder
                  Have you made any changes to the code that you had in the two threads (this and the one in Coldfusion)? Post your latest relevant code.
                  Hey Acoder,

                  As far as i know i haven't made any real changes to it that would effect the city and customer notes, maybe the customer #

                  here is the javascript it is the same for both c1.cfm and c2.cfm.
                  Code:
                  <SCRIPT LANGUAGE="JavaScript" SRC="autocomplete.js"></SCRIPT>
                  	<script type="text/javascript" src="autofill.js"></script>
                  	<script type="text/javascript">
                  
                  var ajax = new sack();
                  	var currentClientID=false;
                  	function getClientData()
                  	{
                  		var clientId = document.getElementById('clientID').value;
                  		if (clientId != "") {
                  			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'];
                  		var resp = ajax.response.split(",");
                        
                        if (ajax.response == "") { // you may want to trim here just in case
                            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 = "";
                  		  
                        } else {
                            var resp = ajax.response.split(",");
                            formObj.cust_company.value = resp[1];
                  		  formObj.fname.value = resp[2];
                  		  formObj.lname.value = resp[3];
                  		  formObj.add1.value = resp[4];
                  		  formObj.city.value = resp[5];
                  		  formObj.state.value = resp[6];
                  		  formObj.zip.value = resp[7];
                  		  formObj.email.value = resp[8];
                  		  formObj.pri_phone.value = resp[9];
                  		  formObj.sec_phone.value = resp[10];
                  		  formObj.notes.value = resp[11];
                        }
                  	}
                  		</script>
                  heres the coldfusion for c1.cfm and c2.cfm. the cfoutput query ticket is used to redisplay what was entered.
                  '
                  Code:
                  <cfoutput query="ticket">
                  Customer Number*:<input type="text" name="clientID" id="clientID" 
                  value="#fk_customer_number#"  ONKEYUP="autoComplete(this,this.form.customer,'value',false)" size="20"/>
                  <cfset fk_customer_number = #fk_customer_number#>
                  </cfoutput>
                  <SELECT NAME="customer" id="options"
                  onChange="this.form.clientID.value=this.options[this.selectedIndex].value;"/>
                  <option value="" selected></option>
                  <cfoutput query="getcustnum">
                  <option value="#fk_custNum#"<cfif #fk_custNum# is #fk_customer_number#>selected</cfif>>#fk_custNum#</option>
                  </cfoutput>
                  </SELECT>
                  <input type="button" class="custnum" name="insert" value="Insert Contact" 
                   onclick="getClientData();"/>
                  <cfoutput query="ticket">
                  Company Name:<input type="text" name="compname" id="cust_company" value="#customer_company#" size="20"/>
                  First Name:<input type="text" name="fname" id="fname" size="20" value="#customer_Fname#"/>
                  Last Name:<input type="text" name="lname" id="lname" value="#customer_Lname#" size="20"/>
                  Address:<input type="text" name="address" value="#customer_add1#" id="add1" size="20"/>
                  City:<input type="text" name="city" id="city" value="#customer_city#" size="20"/>
                  State:<input type="text" name="state" id="state" value="#customer_state#" size="20"/>
                  Zip:<input type="text" name="zip" id="zip" value="#customer_zip#" size="20"/>
                  Email Address:<input type="text" name="email" id="email" value="#customer_email#" size="20"/>
                  Primary Phone:<input type="text" name="priphone" id="pri_phone"value="#customer_pri_phone#" size="20"/>
                  Secondary Phone:<input type="text" name="secphone" id="sec_phone" value="#customer_sec_phone#" size="20"/>
                  Customer Notes:
                  <textarea  maxlength='500' onkeyup='return ismaxlength(this)' onkeydown='return ismaxlength(this)' rows="4" cols="60" name="custnotes" id="notes">#customer_notes#</textarea></cfoutput>
                  here is getclient.cfm
                  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>
                  There are only a few things that i notice. When i go to open up the page for edit. It will have space before the customer number,city and customer notes. The thing is when i am inserting you see no spaces or anything not on the first page or second page. When i go to the second page for edit (its exactly like the form i talked about previously). when i go to look at the edit on the second page it puts more space in front of those 3 fields an i got no clue why.

                  Thank you so much for the help,
                  Rach

                  Comment

                  • bonneylake
                    Contributor
                    • Aug 2008
                    • 769

                    #54
                    Hey Acoder,

                    Well i managed to fix the second page. Instead of the values being the names in the database i changed it to how i had it before which was "form.name of the field" and i was trying to do it "name of the field in database".

                    However, i am still having trouble with the first page an i am not sure how to fix it.
                    When i load the first page it still puts space for customer_number ,city and notes.
                    The thing is with this i have to use the database names in order to get there values so i am not sure how to go around this.Any ideas?

                    Thank you :),
                    Rach

                    Comment

                    • acoder
                      Recognized Expert MVP
                      • Nov 2006
                      • 16032

                      #55
                      When you mention about opening up a page for edit, is that another page?

                      Comment

                      • bonneylake
                        Contributor
                        • Aug 2008
                        • 769

                        #56
                        Originally posted by acoder
                        When you mention about opening up a page for edit, is that another page?
                        Hey Acoder,

                        Basically what i am doing with the form now is trying to make it where you can edit it. I made a copy of the form an just changed the name of it so i can use it for editing. when i go to select the ticket i want to edit when i click on it, it takes me to c1.cfm where i can see what was previously entered, which is the page that i am trouble with.

                        Heres all my pages

                        index.cfm is where you choose the ticket to edit.
                        c1.cfm is the first page where you see the ticket you are editing which shows all the contact information that was entered for that pacific ticket
                        c2.cfm is the second page where you see the contact information for a second time

                        the thing with c1.cfm the only way to display what was originally entered is by using the table field name like customer_number . before on the first page we did not give it values an now i am giving it values.

                        I hope this makes sense,

                        Rach

                        Comment

                        • acoder
                          Recognized Expert MVP
                          • Nov 2006
                          • 16032

                          #57
                          When the space appears, is it when the page loads or after the auto-fill?

                          Comment

                          • bonneylake
                            Contributor
                            • Aug 2008
                            • 769

                            #58
                            Originally posted by acoder
                            When the space appears, is it when the page loads or after the auto-fill?
                            Hey Acoder,

                            the space appears when the page loads. When the page loads it shows what was typed in previously so theres no need to auto-fill unless there changing the customer. But i don't seem to have this trouble with any fields except customer number, city and notes so i am not sure why its only applying it to those 3, you would think it would happen to all.

                            but here is what i have on the first page. the only thing i changed was i added a value to each field.

                            Code:
                            <cfquery name="ticket" datasource="CustomerSupport">
                            		SELECT pk_ticketID,title,priority,status,cost_center,fk_customer_number,
                            customer_company,customer_Fname,customer_Lname,customer_add1,customer_city,customer_state,
                            customer_zip,customer_email,customer_pri_phone,customer_sec_phone,customer_notes,htpp FROM dbo.tbl_CS_ticketMaster
                                    WHERE pk_ticketID = #URL.pk_ticketID#
                            </cfquery>
                            
                            <cfoutput query="ticket">
                            Customer Number*:<input type="text" name="custnum" id="clientID" 
                            value="#fk_customer_number#"  ONKEYUP="autoComplete(this,this.form.customer,'value',false)" size="20"/>
                            <cfset fk_customer_number = #fk_customer_number#>
                            </cfoutput>
                            <SELECT NAME="customer" id="options"
                            onChange="this.form.custnum.value=this.options[this.selectedIndex].value;"/>
                            <option value="" selected></option>
                            <cfoutput query="getcustnum">
                            <option value="#fk_custNum#"<cfif #fk_custNum# is #fk_customer_number#>selected</cfif>>#fk_custNum#</option>
                            </cfoutput>
                            </SELECT>
                            <input type="button" class="custnum" name="insert" value="Insert Contact" 
                             onclick="getClientData();"/>
                            <cfoutput query="ticket">
                            Company Name:<input type="text" name="compname" id="cust_company" value="#customer_company#" size="20"/>
                            First Name:<input type="text" name="fname" id="fname" size="20" value="#customer_Fname#"/>
                            Last Name:<input type="text" name="lname" id="lname" value="#customer_Lname#" size="20"/>
                            Address:<input type="text" name="address" value="#customer_add1#" id="add1" size="20"/>
                            City:<input type="text" name="city"  value="#customer_city#" id="city" size="20"/>
                            State:<input type="text" name="state" id="state" value="#customer_state#" size="20"/>
                            Zip:<input type="text" name="zip" id="zip" value="#customer_zip#" size="20"/>Email Address:<input type="text" name="email" id="email" value="#customer_email#" size="20"/>
                            Primary Phone:
                            <input type="text" name="priphone" id="pri_phone" value="#customer_pri_phone#" size="20"/>
                            Secondary Phone:<input type="text" name="secphone" id="sec_phone" value="#customer_sec_phone#" size="20"/>
                            Customer Notes:
                            <textarea  maxlength='500' onkeyup='return ismaxlength(this)' onkeydown='return ismaxlength(this)' rows="4" cols="60" name="custnotes" id="notes">#customer_notes#</textarea>
                            </cfoutput>
                            Thank you for the help,
                            Rach

                            Comment

                            • acoder
                              Recognized Expert MVP
                              • Nov 2006
                              • 16032

                              #59
                              If it's appearing on page load, that means it can't be the JavaScript which is causing the problem (unless you're calling some JavaScript code onload). This seems like a Coldfusion problem.

                              Comment

                              • bonneylake
                                Contributor
                                • Aug 2008
                                • 769

                                #60
                                Originally posted by acoder
                                If it's appearing on page load, that means it can't be the JavaScript which is causing the problem (unless you're calling some JavaScript code onload). This seems like a Coldfusion problem.
                                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.cf m 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:
                                <!---Inserts record into ticketmaster table--->
                                <cfquery name="insertticketmaster" datasource="CustomerSupport">
                                	exec usp_CS_InsertticketMaster '#Form.title#','#Form.priority#','#Form.status#','#Form.submitted_by#','#Form.last_edited_by#',
                                    '#Form.clientID#','#Form.compname#','#Form.fname#',
                                  '#Form.lname#','#Form.address#','#Form.city#','#Form.state#','#Form.zip#','#Form.email#','#Form.priphone#','#Form.secphone#','
                                    #Form.custnotes#','#Form.costcenterid#','#Form.htpp#'
                                </cfquery>
                                
                                <!---gets the id for ticketmaster an for all of the second part of form.--->
                                <cfset pkID=#insertticketmaster.ID#>
                                
                                <!---inserts/updates record into contacts table. if new inserts if not new will update old record.--->
                                <cfquery name="insertcontacts" datasource="CustomerSupport">
                                exec usp_CS_UpdateInsertcontacts  '#Form.clientID#','#Form.compname#','#Form.fname#', '#Form.lname#','#Form.address#','#Form.city#','#Form.state#','#Form.zip#','#Form.email#','#Form.priphone#','#Form.secphone#','#Form.custnotes#'
                                </cfquery>
                                where is what happens when i update the form
                                Code:
                                <!---Updates TicketMaster Table--->
                                <cfquery name="Update" datasource="CustomerSupport">
                                exec usp_CS_UpdateticketMaster '#Form.ID#','#Form.title#','#Form.priority#','#Form.status#','#Form.last_edited_by#','
                                   #Form.clientID#','#Form.compname#','#Form.fname#','#Form.lname#','#Form.add1#','
                                    #Form.city#','#Form.state#','#Form.zip#','#Form.email#','#Form.priphone#','#Form.secphone#','
                                    #Form.notes#','#Form.cost_center#','#Form.htpp#'
                                </cfquery>
                                
                                <!---Updates/Inserts Contacts table (should only update in this case unless they create a new customer number right here which they shouldn't)--->
                                <cfquery name="insertcontacts" datasource="CustomerSupport">
                                exec usp_CS_UpdateInsertcontacts  '#Form.clientID#','#Form.compname#','#Form.fname#', '#Form.lname#','#Form.add1#','#Form.city#','#Form.state#','#Form.zip#','#Form.email#','#Form.priphone#','#Form.secphone#','#Form.notes#'
                                </cfquery>

                                here is what happens when i submit the entire form for the 2nd an final time
                                Code:
                                <!---Inserts Data for General Information and Contact Information.--->
                                <cfquery name="Update" datasource="CustomerSupport">
                                exec usp_CS_UpdateticketMaster '#Form.ID#','#Form.title#','#Form.priority#','#Form.status#','#Form.last_edited_by#','
                                   #Form.clientID#','#Form.compname#','#Form.fname#','#Form.lname#','#Form.address#','
                                    #Form.city#','#Form.state#','#Form.zip#','#Form.email#','#Form.priphone#','#Form.secphone#','
                                    #Form.custnotes#','#Form.cost_center#','#Form.htpp#'
                                </cfquery>
                                
                                <!---Updates/Inserts Contacts table (should only update in this case unless they create a new customer number right here which they shouldn't)--->
                                <cfquery name="insertcontacts" datasource="CustomerSupport">
                                exec usp_CS_UpdateInsertcontacts  '#Form.clientID#','#Form.compname#','#Form.fname#', '#Form.lname#','#Form.address#','#Form.city#','#Form.state#','#Form.zip#','#Form.email#','#Form.priphone#','#Form.secphone#','#Form.custnotes#'
                                </cfquery>
                                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.

                                Any ideas?

                                Thank you for the help,
                                Rach

                                Comment

                                Working...