473,320 Members | 1,947 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Use onClick to change CF values

139 100+
Hi,

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

Expand|Select|Wrap|Line Numbers
  1. <cfquery name="KWBand1S" dbtype="query">
  2.         select         ClientFK,
  3.                 ResponseLevelFK,
  4.                 PowerRating,
  5.                 WORecDate,
  6.                 ActualCompDate,
  7.                 QuoteACDate,
  8.                 QuotePDate    
  9.         from         getPumpsDate
  10.         where        ResponseLevelFK like 'Standard'
  11.                 and (PowerRating >0
  12.                 and PowerRating <=2.9)
  13.         </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:

Expand|Select|Wrap|Line Numbers
  1. <cfset intDayTotal = 0>
  2.         <cfloop query="KWBand1S">
  3.         <cfset dtFrom = #WORecDate# />
  4.         <cfset dtTo = #ActualCompDate# />
  5.         <cfset ctDays = DateDiff ("d", dtFrom, dtTo)>
  6.         <cfset intDayTotal = intDayTotal + ctDays>
  7.         </cfloop>
  8.         <cfset RecCount = KWBand1S.RecordCount>
  9.             <cfif RecCount NEQ 0>
  10.             <cfset KWBand1SD = intDayTotal/RecCount>
  11.             <cfoutput>#numberFormat(KWBand1SD, "___._")#</cfoutput>
  12.  
  13.             <cfelse>
  14.             -
  15.             </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
Jul 20 '09 #1
21 8288
acoder
16,027 Expert Mod 8TB
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?
Jul 20 '09 #2
ndeeley
139 100+
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.
Jul 20 '09 #3
acoder
16,027 Expert Mod 8TB
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.
Jul 20 '09 #4
ndeeley
139 100+
The first really, as I`m using a company server that only runs CF5 and no ajax (as far as I am aware).
Jul 20 '09 #5
ndeeley
139 100+
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!
Jul 20 '09 #6
acoder
16,027 Expert Mod 8TB
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.
Jul 20 '09 #7
ndeeley
139 100+
Thanks acoder - what I've done is generate all the tables then just hidden them using .css, using a javascript function to open them:

Expand|Select|Wrap|Line Numbers
  1. <script language="JavaScript">
  2. //here you place the ids of every element you want.
  3. var ids=new Array('s1','s2','s3','s4','s5','s6','c1','c2','c3','c4','c5','c6');
  4.  
  5. function switchid(id){    
  6.     hideallids();
  7.     showdiv(id);
  8. }
  9.  
  10. function hideallids(){
  11.     //loop through the array and hide each element by id
  12.     for (var i=0;i<ids.length;i++){
  13.         hidediv(ids[i]);
  14.     }          
  15. }
  16.  
  17. function hidediv(id) {
  18.     //safe function to hide an element with a specified id
  19.     if (document.getElementById) { // DOM3 = IE5, NS6
  20.         document.getElementById(id).style.display = 'none';
  21.     }
  22.     else {
  23.         if (document.layers) { // Netscape 4
  24.             document.id.display = 'none';
  25.         }
  26.         else { // IE 4
  27.             document.all.id.style.display = 'none';
  28.         }
  29.     }
  30. }
  31.  
  32. function showdiv(id) {
  33.     //safe function to show an element with a specified id
  34.  
  35.     if (document.getElementById) { // DOM3 = IE5, NS6
  36.         document.getElementById(id).style.display = 'block';
  37.     }
  38.     else {
  39.         if (document.layers) { // Netscape 4
  40.             document.id.display = 'block';
  41.         }
  42.         else { // IE 4
  43.             document.all.id.style.display = 'block';
  44.         }
  45.     }
  46. }
  47. </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
Jul 21 '09 #8
acoder
16,027 Expert Mod 8TB
That code should work, though the code is badly out of date.
@ndeeley
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.
Jul 21 '09 #9
ndeeley
139 100+
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
Jul 22 '09 #10
acoder
16,027 Expert Mod 8TB
If you want a better, more modern version, I've posted it in your JavaScript thread.
Jul 22 '09 #11
ndeeley
139 100+
I saw - thanks very much for your help!
Jul 22 '09 #12
acoder
16,027 Expert Mod 8TB
You're welcome :)

Did you get the order number/details part working?
Jul 22 '09 #13
ndeeley
139 100+
No....I was going to post it!

Here's my hyperlink:

Expand|Select|Wrap|Line Numbers
  1. <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:

Expand|Select|Wrap|Line Numbers
  1. <cfquery datasource="repairmdb" name="GetClientNo">
  2.     select         ID, 
  3.             WorkshopFK, 
  4.             ClientFK,
  5.             SiteFK,
  6.             WORecdate,
  7.             ResponseLevelFK,
  8.             ClientWONO,
  9.             WorkshopWONO,
  10.             WorkshopJOBNO,
  11.             AssetNO,
  12.             AssetClassFK,
  13.             LocalID,
  14.             ManufacturerFK,
  15.             SerialNO,
  16.             BuildYear,
  17.             ModelFK,
  18.             Frame,
  19.             PowerRating,
  20.             Volts,
  21.             Rmin,
  22.             Amps,
  23.             Ph,
  24.             Head,
  25.             ImpellerDetails,
  26.             Hz,
  27.             ExRated,
  28.             AssetNotes,
  29.             QuoteP,
  30.             QuotePDate,
  31.             Price,
  32.             QuoteAccepted,
  33.             QuoteACDate,
  34.             TargetCDate,
  35.             UQuoteNotes,
  36.             ActualCompDate,
  37.             DeliveryDate,
  38.             FailureReasonFK,
  39.             FRNotes,
  40.             RSLoggedDate,
  41.             RSInspectDate,
  42.             InspectedByFK,
  43.             RSQuotedDate,
  44.             RSApprovedDate,
  45.             RSWIPDate,
  46.             AssignedToFK,
  47.             RSDelDate,
  48.             RSCompDate,
  49.             DateRecordAdded
  50.     from        tblWorkshops
  51.     where        ClientWONO like #ClientWONO#
But its not working...
Jul 22 '09 #14
acoder
16,027 Expert Mod 8TB
What do you mean by not working?

Shouldn't "ClientWONO like #ClientWONO#" be "ClientWONO = #ClientWONO#"? Is ClientWONO a string or a number?
Jul 22 '09 #15
ndeeley
139 100+
Yes, sorry i posted the wrong code.

The actual hyperlinking is this:

Expand|Select|Wrap|Line Numbers
  1. <td style="width: 100px;"><a href="http://marlin/engeastl/scripts/RepairWorkshops/Devaction_search2.cfm?WorkshopWONO='#WorkshopWONO#'">#WorkshopWONO#</a></td>
and the processing code is:

Expand|Select|Wrap|Line Numbers
  1. <cfquery datasource="repairmdb" name="GetClientNo">
  2.     select         ID, 
  3.             WorkshopFK, 
  4.             ClientFK,
  5.             SiteFK,
  6.             WORecdate,
  7.             ResponseLevelFK,
  8.             ClientWONO,
  9.             WorkshopWONO,
  10.             WorkshopJOBNO,
  11.          DateRecordAdded
  12.     from        tblWorkshops
  13.     where        WorkshopWONO = '#WorkshopWONO#'
WorkshopWONO is a string (tho actually a number stored in a text field, for reasons that they don't all have a WONO).

The processing page appears, but tells me that no record is found, so it's not processing the received value properly.
Jul 22 '09 #16
acoder
16,027 Expert Mod 8TB
You don't need the single quotes around WorkshopWONO, so the link should be:
Expand|Select|Wrap|Line Numbers
  1. Devaction_search2.cfm?WorkshopWONO=#WorkshopWONO#
Note that you could still store it as a number and use NULL for non-values.
Jul 22 '09 #17
ndeeley
139 100+
That's grand - thanks acoder!

Neil
Jul 22 '09 #18
acoder
16,027 Expert Mod 8TB
Though it's probably not as much of a problem with an internal application (except with an programming-savvy disgruntled employee), a point to bear in mind is that you should sanitise inputs before using them in queries (e.g. use cfqueryparam), otherwise you could be subject to an SQL injection attack.
Jul 22 '09 #19
ndeeley
139 100+
Ok...for the non technically minded (ie given a book on CF and dumped in the deep end) what is an SQL injection attack?
Jul 22 '09 #20
acoder
16,027 Expert Mod 8TB
This article should help, though maybe one or two things may not apply to Coldfusion 5. For a general link on SQL injection, see the Wikipedia entry.
Jul 22 '09 #21
ndeeley
139 100+
Interesing, and not about a cure for Swine Flu like I first thought...

I'm cleaning up my code so I shall apply all the instructions within!

Cheers acoder!
Neil
Jul 24 '09 #22

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Zalek Bloom | last post by:
Hello, Here is my problem: I am displaying to a user a row of buttons. Depending on which button user presses, I want to go to a different URL and to give a different value to a hidden...
8
by: KS | last post by:
Just to show some code to show the consept. <img id="date" onclick="javascript:show_calendar();" src="/PlexSysWeb/images/show-calendar.gif" width=20 height=18 border=0> What i want the...
10
by: WindAndWaves | last post by:
Hi Gurus I have the following code: function CI(ImgN, Alt){ if( document.getElementById && document.getElementById('il') ){ var d=document.getElementById('il');
1
by: Dark Magician | last post by:
Comrades: Am trying to build a UI widget. I'm sure part of the problem is proper variable scope or object reference, and part of the problem may be the way I'm calling the function, but, here...
1
by: Ben | last post by:
Hi, I have a number of images whose src's are changed when a button is pressed. At the moment the href is also changed and the images are opened. However I have a function which opens the...
5
by: johnsuth | last post by:
I want to produce a trivial demonstration of dynamic modification. I thought that pressing a button might change its color. I studied O'Reillys books and successfully created the button with a...
2
by: gakman_2006 | last post by:
I am trying to get an onclick event to pass some values to a function to display in an alert box for now. I can get it sort of working but now the way I need it. I will be changing the alert in the...
12
by: Andrew C | last post by:
Hi, folks. I've recently been doing a few simple tests and experiments. As a result, I've noticed that, in dealing with 'onclick', IE seems less able than Firefox to keep up with rapid clicking....
1
by: sourcie | last post by:
I am changing an existing quiz found on "JavaScriptKit.com Multiple Choice Quiz" I have an image. Instead of using the radio buttons with the normal true/false question, I want to place two...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.