Hi,
I have a CF query that extracts all the information from a db and sprays in into a table.
I'd like a drop down list box that can filter this data based on the value in the box. IE at loading it shows 'All' jobs, but when changed to 'Completed' it just shows Completed jobs. I'd like to use the onChange event to trigger this.
What's the best way of achieving this in Cold Fusion?
Thanks
Neil
9 14380
The newer versions of Coldfusion have tags that probably allow you to do this without much knowledge of JavaScript/Ajax. If you're using an older version, then you'll need to have at least some basic JavaScript knowledge unless you use a submit button instead of directly changing via an onchange.
As for the Coldfusion part, you could use a Query of Queries together with a cached query which queries the query returned rather than the database each time, though it's not necessary.
Should it be instant, or can the change happen with a page change?
I'm using CF MX (5 I think) so that rules out any easy option! I am using a submit button at the moment, with a form action to a copy of the page. I'd rather keep it all in one page - should I set up a variable and use IsDefined to find if the submit button has attributed it a value?
Ah,
I think I have done it but with one problem.
I created a form with the same action as the page: -
<form action="TB_MyTasksGIS.cfm" method="post">
-
Tasks to show
-
<select name="changeitem" class="droplist">
-
<option value="*">All</option>
-
<option value="Not Begun">Not Begun</option>
-
<option value="Started">Started</option>
-
<option value="Pending">Pending</option>
-
<option value="Completed">Completed</option>
-
</select>
-
<input type="submit" value="submit" class="buttons">
-
</form>
-
then set up an cf IsDefined to catch it: -
<cfif IsDefined("form.changeitem")>
-
-
<cfquery datasource="taskbook" name="GetMyTasks">
-
select T.ID,
-
T.WorkID,
-
T.CustomerName,
-
T.Dept,
-
T.Location,
-
T.ContactNo,
-
T.EmailAddress,
-
T.TaskTypeFK,
-
T.TaskDetails,
-
T.ChargeableYN,
-
T.ChargeCode,
-
T.JobStatusFK,
-
T.AssignedToFK,
-
T.AssignedNotes,
-
T.AssignedByFK,
-
T.AssignedStatusFK,
-
T.StartDate,
-
T.PendReasonFK,
-
T.CompletionDate,
-
T.TimeTaken,
-
T.CompletionNotes,
-
T.FileServerFK,
-
T.FileLoc,
-
T.RequestDate,
-
T.AddedBy,
-
S.FirstName,
-
S.Surname,
-
S.LoginName
-
from tblTaskBooker T left outer join tblStaff S
-
on T.AddedBy = S.LoginName
-
where AddedBy = '#username#' and JobStatusFK = '#form.changeitem#'
-
order by ID
-
</cfquery>
-
-
<cfelse>
-
-
..same code again with no "and JobStatusFK"
-
-
</cfif>
-
-
which all works fine - I just now can't get the table to show all the records again if selected from the list. I'm assuming my value in the select 'All' field is wrong. I've tried ="" and ="*" but neither work. Any idea what I am doing wrong?
You need to get rid of the condition to show all the records.
You can use an empty string and use cfparam to give a default value, then when "changeitem" is empty, you can remove the condition.
In fact, you could have one query and have the cfif around the condition: - where AddedBy = '#username#'
-
<cfif form.changeitem NEQ "">
-
and JobStatusFK = '#form.changeitem#'
-
</cfif>
You should also be using cfqueryparam for any user input into a query.
All changed!
Brilliant - thanks very much. Saved me a lot of code!
Cheers
Neil
Hi,
I've used this script successfully but now have a small amendment.
I have two of the same scripts on the same page, but with different form.changeitem names. obviously because of the default at the top when I use either of the forms the other defaults back to showing that value, when I want to keep it displaying the information the user has already selected: -
<cfparam name="form.changeitem" default="">
-
<cfquery datasource="taskbook" name="GetMyTasks">
-
select T.ID,
-
T.WorkID,
-
T.CustomerName,
-
T.Dept,
-
T.Location,
-
T.ContactNo,
-
T.EmailAddress,
-
T.TaskCategoryFK,
-
T.TaskTypesFK,
-
T.TaskDetails,
-
T.ChargeableYN,
-
T.ChargeCode,
-
T.JobStatusFK,
-
T.AssignedToFK,
-
T.AssignedNotes,
-
T.AssignedByFK,
-
T.AssignedStatusFK,
-
T.StartDate,
-
T.PendReasonFK,
-
T.CompletionDate,
-
T.TimeTaken,
-
T.CompletionNotes,
-
T.FileServerFK,
-
T.FileLoc,
-
T.RequestDate,
-
T.AddedBy,
-
S.FirstName,
-
S.Surname,
-
S.LoginName
-
from tblTaskBooker T left outer join tblStaff S
-
on T.AddedBy = S.LoginName
-
where AddedBy = '#username#'
-
<cfif form.changeitem NEQ "">
-
and JobStatusFK = '#form.changeitem#'
-
</cfif>
-
order by RequestDate desc
-
</cfquery>
-
-
<cfparam name="form.changeAitem" default="">
-
-
-
<cfquery datasource="taskbook" name="GetMyATasks">
-
select T.ID,
-
T.WorkID,
-
T.CustomerName,
-
T.Dept,
-
T.Location,
-
T.ContactNo,
-
T.EmailAddress,
-
T.TaskCategoryFK,
-
T.TaskTypesFK,
-
T.TaskDetails,
-
T.ChargeableYN,
-
T.ChargeCode,
-
T.JobStatusFK,
-
T.AssignedToFK,
-
T.AssignedNotes,
-
T.AssignedByFK,
-
T.AssignedStatusFK,
-
T.StartDate,
-
T.PendReasonFK,
-
T.CompletionDate,
-
T.TimeTaken,
-
T.CompletionNotes,
-
T.FileServerFK,
-
T.FileLoc,
-
T.RequestDate,
-
T.AddedBy,
-
S.FirstName,
-
S.Surname,
-
S.LoginName
-
from tblTaskBooker T left outer join tblStaff S
-
on T.AssignedByFK = S.LoginName
-
where AssignedStatusFK = 'Assigned' and AssignedToFK = '#username#' and AddedBy <> '#username#'
-
<cfif form.changeAitem NEQ "">
-
and JobStatusFK = '#form.changeAitem#'
-
</cfif>
-
order by RequestDate desc
-
</cfquery>
-
How can I ensure that the lower form shows the form.ChangeAitem value instead of resetting it back to default when the page refreshes? I've tried using: -
<cfif Not IsDefined ("form.changeitem")
-
..set default
-
<cfself>
-
..run code with form.changeitem value
-
</cfif>
-
but I can't get this to work!
Thanks
How does the page refresh? Is it a form post?
If it is, you can pass the current value(s) of changeitem as a hidden field(s).
Yes, it is. I'll try passing the value as a hidden field in the url...
Let you know how I get on.
Thanks acoder!
A quick note: if you pass a value in the URL, it would be accessed as url.fieldname . To have the value accessible as form.fieldname , you need to post the form.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: shlomi.schwartz |
last post by:
Hi All,
Is it possible to open the select (ComboBox) drop down list by script?
|
by: PB |
last post by:
I have an aspx with 4 Drop-Down list boxes on it. All the list values are
hard-coded in the aspx.
I want a client-side JavaScript function to select a value in each of those
DDLs.
I can...
|
by: tjonsek |
last post by:
I have two drop down boxes on a form. One feeds the second a list
options based on user selection. With the second drop down, I want code
that displays dynamic text in a <div> based on whatever the...
|
by: Rob Meade |
last post by:
Hi all,
I post back to my page if the form hasn't been submitted with the required
information. I would like to with a little javascript, auto-select an
option in the drop down list on my page....
|
by: magix |
last post by:
I have an drop down list
let say:
<SELECT name="id" id="id" OnClick="Skip()">
<option value="0"></option>
<option value="1">Item 1</option>
<option value="2">Item 2</option>
<option...
|
by: slekshmipriya |
last post by:
Hai friends.I have a pblm with my drop down list onchange event.The pblm is as follow
I have a drop drown list with items 1,2 ,3 etc.
On selecting an item from the drop down list i want to...
|
by: Hanoodah |
last post by:
Good morning all,
Please I need help in a form that I have designed to fill user information. This form needs two drop-down list about specific date, one about contract date, and the other about...
|
by: crazychrisy54 |
last post by:
Hi there
I have a option, select drop down list which a user can open. My page
however refreshes very frequently and when this occurs the selected
drop down list will pop back up. The user then...
|
by: matamala Naresh |
last post by:
in the table 3 fields are available (id,name,dept)
iam creating drop down list with names.when user selects name in the drop down we need to auto pop up the department(dept) of that selected name in...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |