Use onClick to change CF values

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ndeeley
    New Member
    • Mar 2007
    • 139

    Use onClick to change CF values

    Hi,

    I have created several queries which produce the same data based on a slightly difference set of variables:

    Code:
    <cfquery name="KWBand1S" dbtype="query">
    		select 		ClientFK,
    				ResponseLevelFK,
    				PowerRating,
    				WORecDate,
    				ActualCompDate,
    				QuoteACDate,
    				QuotePDate	
    		from 		getPumpsDate
    		where		ResponseLevelFK like 'Standard'
    				and (PowerRating >0
    				and PowerRating <=2.9)
    		</cfquery>
    The only variable that changes is the Power Rating - it has various ranges and I just created a query for each one.

    The output gets mashed up so that the number of records are counted and divided by a count of the days in the date range to produce a number N:

    Code:
    <cfset intDayTotal = 0>
    		<cfloop query="KWBand1S">
    		<cfset dtFrom = #WORecDate# />
    		<cfset dtTo = #ActualCompDate# />
    		<cfset ctDays = DateDiff ("d", dtFrom, dtTo)>
    		<cfset intDayTotal = intDayTotal + ctDays>
    		</cfloop>
    		<cfset RecCount = KWBand1S.RecordCount>
    			<cfif RecCount NEQ 0>
    			<cfset KWBand1SD = intDayTotal/RecCount>
    			<cfoutput>#numberFormat(KWBand1SD, "___._")#</cfoutput>
    				
    			<cfelse>
    			-
    			</cfif>
    Which all works. But now I need to output the records in a table - fine, except that I have 12 different query sets to work from.

    Is there anyway to have the source of my output table as a variable whose value is changed when the user clicks on the number N - ie showing the records in that query set? I was thinking that an onclick event might change the variable value, but don't know how.

    Thanks
    Neil
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    This would be more of a JavaScript question, but you could use the same query using <cfif> to decide which power rating to use.

    Do you want only one number set to be displayed at a time, or would the whole lot do? Also, does the change have to happen instantly or is a page unload/reload not a problem?

    Comment

    • ndeeley
      New Member
      • Mar 2007
      • 139

      #3
      hi Acoder,

      how would I achieve this? i only want it to display one number change at a time, but obviously want to give the user the choice of changing it (whether clicking on the number or selecting the criteria from a drop down list box).

      I need instantaneous update really.

      Comment

      • acoder
        Recognized Expert MVP
        • Nov 2006
        • 16032

        #4
        You have at least two choices:
        1. Load all the data into JavaScript data structures, e.g. arrays to use to update the table. Use Coldfusion to generate the JavaScript code.
        2. Use Ajax. Make a Http request to a Coldfusion page which gets the correct data for the passed parameter.

        Which one would you be more comfortable with?

        Note: Coldfusion 8 has a few Ajax tags, but I personally haven't really looked into them, because I'm quite comfortable with JavaScript/Ajax.

        Comment

        • ndeeley
          New Member
          • Mar 2007
          • 139

          #5
          The first really, as I`m using a company server that only runs CF5 and no ajax (as far as I am aware).

          Comment

          • ndeeley
            New Member
            • Mar 2007
            • 139

            #6
            The only other thing i was thinking of doing was generating a table from each query, then hiding it until the user clicks on a number, which would show the table, but I`m guessing that a javascript question!

            Comment

            • acoder
              Recognized Expert MVP
              • Nov 2006
              • 16032

              #7
              Yes, that would be another option, but you would need to use Coldfusion to generate it.

              Note that Ajax support is more to do with the browser rather than the version of Coldfusion, so it's still an option for you.

              Comment

              • ndeeley
                New Member
                • Mar 2007
                • 139

                #8
                Thanks acoder - what I've done is generate all the tables then just hidden them using .css, using a javascript function to open them:

                Code:
                <script language="JavaScript">
                //here you place the ids of every element you want.
                var ids=new Array('s1','s2','s3','s4','s5','s6','c1','c2','c3','c4','c5','c6');
                
                function switchid(id){	
                	hideallids();
                	showdiv(id);
                }
                
                function hideallids(){
                	//loop through the array and hide each element by id
                	for (var i=0;i<ids.length;i++){
                		hidediv(ids[i]);
                	}		  
                }
                
                function hidediv(id) {
                	//safe function to hide an element with a specified id
                	if (document.getElementById) { // DOM3 = IE5, NS6
                		document.getElementById(id).style.display = 'none';
                	}
                	else {
                		if (document.layers) { // Netscape 4
                			document.id.display = 'none';
                		}
                		else { // IE 4
                			document.all.id.style.display = 'none';
                		}
                	}
                }
                
                function showdiv(id) {
                	//safe function to show an element with a specified id
                		  
                	if (document.getElementById) { // DOM3 = IE5, NS6
                		document.getElementById(id).style.display = 'block';
                	}
                	else {
                		if (document.layers) { // Netscape 4
                			document.id.display = 'block';
                		}
                		else { // IE 4
                			document.all.id.style.display = 'block';
                		}
                	}
                }
                </script>
                Where the div has the ID shown in the function.

                One other thing tho - if I include in my table another link (a particular order number for example) can I use CF to open that link, carrying the order number variable to another bit of cfm script? (in this case a script that shows the order details for that number, which I already have).

                Thanks for your help
                Neil

                Comment

                • acoder
                  Recognized Expert MVP
                  • Nov 2006
                  • 16032

                  #9
                  That code should work, though the code is badly out of date.
                  Originally posted by ndeeley
                  One other thing tho - if I include in my table another link (a particular order number for example) can I use CF to open that link, carrying the order number variable to another bit of cfm script? (in this case a script that shows the order details for that number, which I already have).
                  Either use the same method, i.e. keep hidden initially and show with JavaScript, or use Ajax to show only the ones required as and when needed. The advantage of the first way is that you've already got something similar working, but if there's a lot of stuff, it may affect page load.

                  Comment

                  • ndeeley
                    New Member
                    • Mar 2007
                    • 139

                    #10
                    Yes, I didn't write it - I found it on the web, and it workd, so I used it. I haven't done any training in Javascript. Unfortunately I`m in one of those jobs where you get trained on something, use it for a while, and then not for 12 months...

                    Thanks for your comments - I'll give it a go!

                    Cheers
                    Neil

                    Comment

                    • acoder
                      Recognized Expert MVP
                      • Nov 2006
                      • 16032

                      #11
                      If you want a better, more modern version, I've posted it in your JavaScript thread.

                      Comment

                      • ndeeley
                        New Member
                        • Mar 2007
                        • 139

                        #12
                        I saw - thanks very much for your help!

                        Comment

                        • acoder
                          Recognized Expert MVP
                          • Nov 2006
                          • 16032

                          #13
                          You're welcome :)

                          Did you get the order number/details part working?

                          Comment

                          • ndeeley
                            New Member
                            • Mar 2007
                            • 139

                            #14
                            No....I was going to post it!

                            Here's my hyperlink:

                            Code:
                            <td class="tdpump" style="width: 120px;"><a href="http:\\marlin\engeastl\scripts\repairworkshops\devaction_search2.cfm?ClientWONO=#ClientWONO#">#ClientWONO#</a></td>
                            And the script that processes it:

                            Code:
                            <cfquery datasource="repairmdb" name="GetClientNo">
                            	select 		ID, 
                            			WorkshopFK, 
                            			ClientFK,
                            			SiteFK,
                            			WORecdate,
                            			ResponseLevelFK,
                            			ClientWONO,
                            			WorkshopWONO,
                            			WorkshopJOBNO,
                            			AssetNO,
                            			AssetClassFK,
                            			LocalID,
                            			ManufacturerFK,
                            			SerialNO,
                            			BuildYear,
                            			ModelFK,
                            			Frame,
                            			PowerRating,
                            			Volts,
                            			Rmin,
                            			Amps,
                            			Ph,
                            			Head,
                            			ImpellerDetails,
                            			Hz,
                            			ExRated,
                            			AssetNotes,
                            			QuoteP,
                            			QuotePDate,
                            			Price,
                            			QuoteAccepted,
                            			QuoteACDate,
                            			TargetCDate,
                            			UQuoteNotes,
                            			ActualCompDate,
                            			DeliveryDate,
                            			FailureReasonFK,
                            			FRNotes,
                            			RSLoggedDate,
                            			RSInspectDate,
                            			InspectedByFK,
                            			RSQuotedDate,
                            			RSApprovedDate,
                            			RSWIPDate,
                            			AssignedToFK,
                            			RSDelDate,
                            			RSCompDate,
                            			DateRecordAdded
                            	from		tblWorkshops
                            	where		ClientWONO like #ClientWONO#
                            But its not working...

                            Comment

                            • acoder
                              Recognized Expert MVP
                              • Nov 2006
                              • 16032

                              #15
                              What do you mean by not working?

                              Shouldn't "ClientWONO like #ClientWONO#" be "ClientWONO = #ClientWONO#"? Is ClientWONO a string or a number?

                              Comment

                              Working...