Autofill form fields, almost working

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • bonneylake
    Contributor
    • Aug 2008
    • 769

    #31
    Hey Acoder,

    Well i like your idea so i added a button so now when they click on the button it inserts.

    I am only running into 1 last problem. The thing with the customer number is that it appears on 2 pages. The first page is where you fill it out. An then the second page is where you view what you had typed in on the first page and also make changes in case of an error. The problem i am having is on the 2nd page.

    If i do not select something from the drop down box an instead create a new customer number and click submit on the first page. Then on the second page it will bring up an error saying the form field can not be found (for the drop down box). An was wondering how could i give it the value of nothing if a value in the drop down box is not selected?

    here is what i got in the form
    Code:
    Customer Number*:<input type="text" name="custnum" value="#Form.custnum#"  id="clientID" ONKEYUP="autoComplete(this,this.form.customer,'value',false)"   onChange="validate(this.form.custnum,'Customer Number')"/></cfoutput>
    <SELECT NAME="customer" id="options"
    onChange="this.form.custnum.value=this.options[this.selectedIndex].value;javascript:getClientData();">
    <cfoutput query="getcustnum">
    <option value="#fk_custNum#" <cfif #fk_custNum# is #form.customer#>selected</cfif>>#fk_custNum#</option>
    </cfoutput>
    </SELECT>
    <input type="button" class="custnum" name="insert" value="Insert Contact" 
       onclick="javascript:getClientData();">
    Thank you in advance for all the help :),
    Rach

    Comment

    • acoder
      Recognized Expert MVP
      • Nov 2006
      • 16032

      #32
      Do you have an empty value for the drop-down? You should have this selected initially. If you enter a new number that doesn't match, this is the value that should be selected.

      Comment

      • bonneylake
        Contributor
        • Aug 2008
        • 769

        #33
        Hey Acoder,

        No i don't have a empty value for the drop-down. An when the drop down box loads when i fill out the information for the first time it says 1. but I changed it now so when it loads it says nothing.

        this is what i did for the first page on the select button
        Code:
        <SELECT NAME="customer" id="options"
        onChange="this.form.custnum.value=this.options[this.selectedIndex].value;">
        <cfoutput query="getcustnum">
        <option value="" selected></option>
        <option value="#fk_custNum#">#fk_custNum#</option>
        </cfoutput>
        </SELECT>
        but i am not sure how to apply this to the second page since its suppose to get whatever was choosen/writen on the first page.the only way i can think of is to do it in the table but if i do it in the table i have to put 0 an can't just leave it saying nothing in the table.

        here is what i have on the second page right now but this doesn't worth with no value in there

        Code:
        <SELECT NAME="customer" id="options"
        onChange="this.form.custnum.value=this.options[this.selectedIndex].value;javascript:getClientData();">
        <cfoutput query="getcustnum">
        <option value=""></option>
        <option value="#fk_custNum#" <cfif #fk_custNum# is #form.customer#>selected</cfif>>#fk_custNum#</option>
        </cfoutput>
        </SELECT>
        any suggestions? Thank you again for the help,

        Rach

        Comment

        • acoder
          Recognized Expert MVP
          • Nov 2006
          • 16032

          #34
          If the second page is only for viewing the results, just display the results using Coldfusion. The user can always go back to change something.

          PS. you don't need the "javascript :" protocol in most cases, especially not in event handlers.

          Comment

          • bonneylake
            Contributor
            • Aug 2008
            • 769

            #35
            Hey Acoder

            about the javsacript protocol are you meaning to take this part out javascript:getC lientData()?

            an well the thing is i am trying to display the one that is selected from the first page onto the second page so basically would it still work if i took the cfif selected part out?

            Thank you,
            Rach

            Comment

            • acoder
              Recognized Expert MVP
              • Nov 2006
              • 16032

              #36
              Just the "javascript :" part, so for example, "javascript:get ClientData()" becomes getClientData() .

              The second question is about Coldfusion, but I'll answer it here. Use a cfparam for the form.customer to set a default value of "".

              Comment

              • bonneylake
                Contributor
                • Aug 2008
                • 769

                #37
                Originally posted by acoder
                Just the "javascript :" part, so for example, "javascript:get ClientData()" becomes getClientData() .

                The second question is about Coldfusion, but I'll answer it here. Use a cfparam for the form.customer to set a default value of "".
                Hey Acoder,

                yep that worked,yay :). but i got one last problem. which sorry took so long to respond to this just got to come back to work today. I added one line to my drop down box. the line is bolded.

                Code:
                <SELECT NAME="customer" id="options"
                onChange="this.form.custnum.value=this.options[this.selectedIndex].value;">
                <cfoutput query="getcustnum">
                [B]<option value="" selected></option>[/B]
                <option value="#fk_custNum#">#fk_custNum#</option>
                </cfoutput>
                </SELECT>
                but anyway with that line in there it makes the drop down options appear as such

                1024

                444

                etc....

                when needs to appear like this

                1024
                444
                etc....

                how could i still keep that line in there without it display my drop down box with spaces in it?

                Thank you again for all the help :),
                Rach

                Comment

                • acoder
                  Recognized Expert MVP
                  • Nov 2006
                  • 16032

                  #38
                  You need to keep that line outside the loop (before it), otherwise in the loop, you're adding two options for each iteration.

                  Comment

                  • bonneylake
                    Contributor
                    • Aug 2008
                    • 769

                    #39
                    Originally posted by acoder
                    You need to keep that line outside the loop (before it), otherwise in the loop, you're adding two options for each iteration.
                    Hey Acoder,

                    yep that was it. wow can't believe it's working! But THANK YOU SO MUCH FOR ALL THE HELP!!! you have no idea how awesome it is to see it working :). But thank you again for all the help, you are awesome!

                    Rach

                    Comment

                    • acoder
                      Recognized Expert MVP
                      • Nov 2006
                      • 16032

                      #40
                      You're welcome. Glad it's working. Pretty long thread for one which has got "almost working" in the title! ;)

                      Comment

                      • bonneylake
                        Contributor
                        • Aug 2008
                        • 769

                        #41
                        Originally posted by acoder
                        You're welcome. Glad it's working. Pretty long thread for one which has got "almost working" in the title! ;)
                        Hey Acoder,

                        yeah i thought it was "almost working" but i was wrong. An still wrong now. i got another problem an i can't even begin to really explain it. This morning i got on to the form an when i tried to auto fill the form it wouldn't work. i checked the database an it has entry's. But when i tried to auto fill it it wouldn't worked. After refreshing it a few times an messing with it i got it to work. But today i have noticed this problem a lot. when i came back to lunch it didn't work. an when i let it sit for a few minutes an tried to change it i ran into this problem as well. an i am wondering could anything in the autofill and the drop down box affect this problem or could it be a loading problem on my part? i know we been having loading problems at work. but everything else for my form works fine even with the slow internet an few problems we have had. If you got any suggestions let me know because needs to work all the time an this seems to continue to be a problem. if you need me to repost everything i got i will.

                        Thank you,
                        Rach

                        Comment

                        • acoder
                          Recognized Expert MVP
                          • Nov 2006
                          • 16032

                          #42
                          Have you made any changes since the last version that you've posted in this thread?

                          Comment

                          • bonneylake
                            Contributor
                            • Aug 2008
                            • 769

                            #43
                            Originally posted by acoder
                            Have you made any changes since the last version that you've posted in this thread?
                            Hey Acoder,

                            As far as i know i don't think so, the only thing i think i might of changed is the Javascript that appears with the form, i know i didn't mess with any of the files that work with it. Here is what i got on the Javascript part.i messed with the function initFormEvents part.

                            Javascript that appears on the form page
                            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('clientID').onblur = getClientData;--->
                            		document.getElementById("insert").onclick = getClientData;
                              <!---      document.getElementById('clientID').focus();
                                    document.getElementById("options").onchange = getClientData;--->
                            		
                            	
                            	}
                            	
                            	
                            	window.onload = initFormEvents;
                            	</script>
                            an here is the html i have in case you wanna see this.

                            Code:
                            Customer Number*:<input type="text" name="custnum" id="clientID" value=""  ONKEYUP="autoComplete(this,this.form.customer,'value',false)"  />
                            <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#">#fk_custNum#</option>
                            </cfoutput>
                            </SELECT>
                            <input type="button" class="custnum" name="insert" value="Insert Contact" 
                               onclick="getClientData();">
                            Thank you :),
                            Rach

                            Comment

                            • acoder
                              Recognized Expert MVP
                              • Nov 2006
                              • 16032

                              #44
                              The initFormEvents function is now pretty much useless because you've already set the onclick inline in the button.

                              When you say it sometimes doesn't work, what exactly do you mean? Can you give an example? You do realise that with the current code, the form will only autofill on clicking the button?

                              Comment

                              • bonneylake
                                Contributor
                                • Aug 2008
                                • 769

                                #45
                                Hey Acoder,

                                well basically i would get on there an choose a number an then click on the button an it wouldn't auto fill the form. i ran in to this problem at certain points in the day yesterday.at one point it would work. an at others i would click on the button several times saying come on auto fill. i even had a point where i choose a number an clicked on the button and nothing happened, so i went online an checked my email i came back a minute later and the form was auto filled. but today it seems to be working fine. i might of been doing something wrong on account of i ended up getting a cold over the weekend so my mind is not as there so i might of chosen the wrong customer number. although thought i tried several different ones. it could of been a problem with the intranet because the networking guys had to fix some problems yesterday so it could be a mixture of both. but for now i am just going to keep an eye out on it an see what happens.

                                But thank you again for the help :),
                                Rach

                                Comment

                                Working...