Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to understand the world of checkboxes 1

Status
Not open for further replies.

johnhig

MIS
Jun 25, 2007
54
US
Hi Everyone,
I hope you can help me understand the world of checkboxes.
I am confused on how I can make this work.

I am displaying list of data based upon the following query.
<CFQUERY NAME="GetTasks" DATASOURCE="intranet" DBTYPE="ODBC">
SELECT Tasks.ProjectID, Tasks.TaskID, Tasks.Customer, Tasks.jobtype, Tasks.labor, Tasks.travel, inventoryused.projectID, inventoryused.partstaskid, inventoryused.tasktype, inventoryused.partname, inventoryused.partdescription, inventoryused.qty, inventoryused.price
FROM Tasks, inventoryused
WHERE tasks.PROJECTID = #ProjectID# AND inventoryused.projectid = #ProjectID#
</CFQUERY>

One of the columns is a checkbox that I would like the user to be able to check (And there maybe multiple) click the continue button. The following code is the list where they can check.
<CFOUTPUT>
<TR>
<TD NOWRAP CLASS="DataTD" ID="firstcolumnsolid"><FONT CLASS="DataFont"><input name="billed" type="checkbox" value="Yes" /></FONT></TD>
<TD NOWRAP CLASS="DataTD" ID="firstcolumnsolid"><A HREF="/intranet/projecttracking/taskdetails.cfm?Reason=Modify&ProjectID=#ProjectID#&TaskID=#TaskID#"><FONT CLASS="DataFont">#GetTasks.TaskID#</FONT></A></TD>
<TD NOWRAP CLASS="DataTD"><A HREF="/intranet/projecttracking/taskdetails.cfm?Reason=Modify&ProjectID=#ProjectID#&TaskID=#TaskID#"><FONT CLASS="DataFont">#GetTasks.Customer# </FONT></A></TD>
<TD NOWRAP CLASS="DataTD"><A HREF="/intranet/projecttracking/taskdetails.cfm?Reason=Modify&ProjectID=#ProjectID#&TaskID=#TaskID#"><FONT CLASS="DataFont">#GetTasks.JobType#</FONT></A></TD>
<TD NOWRAP CLASS="DataTD"><FONT CLASS="DataFont">#GetTasks.Labor#</FONT></TD>
<TD NOWRAP CLASS="DataTD"><FONT CLASS="DataFont">#GetTasks.Travel#</FONT></TD>
<TD NOWRAP CLASS="DataTD">&nbsp;</TD>
<TD NOWRAP CLASS="DataTD">&nbsp;</TD>
<TD NOWRAP CLASS="DataTD" ALIGN="right" ID="lastcolumnsolid">&nbsp;</TD>
<TD NOWRAP CLASS="DataTD" ALIGN="right" ID="lastcolumnsolid">&nbsp;</TD>
</TR>
</CFOUTPUT>

And this is where I get confused, because I think my next step is to have a <CFIF IsDefined(Form.billed)> on my action page. Which would update the field on the database to a yes.

Am I doing this correctly? Or am I way off base?

Thanks John
 
I assume you are displaying one record based on the project ID. So, if the user checks the "Billed" checkbox, it will exist in the form scope on the action page. If they didn't, it won't. IsDefined() is the way to go. Just wrap your update code in the CFIF. Don't forget to pass the ID values in a hidden form so you have something on which to base the WHERE clause in your update statement.

Phil Hegedusich
Senior Programmer/Analyst
IIMAK
-----------
Pity the insomniac dyslexic agnostic. He stays up all night, wondering if there really is a dog.
 
No I am not. The ProjectID has several tasks associated with it. So I am looking at allowing the funcationality of
checking any particular task to bill it.


I think that if it was just the project then I would be able to understand the checkbox.

John
 
If you want to update any records based on the checkbox being clicked, you first need to check if the checkbox exists on teh action page. Your thought about <CFIF IsDefined(Form.billed)> is the right approach.

You can do something like:
Code:
<cfif isdefined("Form.billed")>
  <cfquery>
    ...
  </cfquery>
<cfelse>
  something else
</cfif>

____________________________________
Just Imagine.
 
so on my action page I have the following code:

<cfif IsDefined("form.bill_parts")>
<CFLOOP INDEX="Checked_ITEM" LIST="#Form.bill_parts#">
<CFQUERY NAME="Billing" DATASOURCE="intranet" DBTYPE="ODBC">
UPDATE InventoryUsed
SET
billed ='Yes',
bill_date='#dateFormat(now())#'
WHERE ProjectID = #FORM.ProjectID# AND PartsTaskID = #FORM.PartsTaskID#
</CFQUERY>
</CFLOOP>
</cfif>

I am not sure if the loop is necessary. My thought was to update the record if more than one record is checked.

John
 
In your original code snippet you have only one checkbox named Form.bill_parts. How many checkboxes will there be? Are all of them going to be named bill_parts?

If you have, let's say, three checkboxes and all of them are named bill_parts then the <cfif> will always return true -- because one of the three was clicked and submitted. To use the <cfloop> you'd need to identify one checkbox from the other and do the updates accordingly.

You'd need to, instead, do something like this: name the checkboxes in a sequential order bill_parts1,bill_parts2,bill_parts3. Then, on the action page loop of the checkboxes and update accordingly.

Code:
  <cfif isdefined("form.bill_parts[x]")>
    <CFLOOP INDEX="Checked_ITEM" from="1" to="len(bill_parts[x])">
    <CFQUERY NAME="Billing" DATASOURCE="intranet" DBTYPE="ODBC">
        UPDATE InventoryUsed
        SET
        billed ='Yes',
        bill_date='#dateFormat(now())#'
        WHERE ProjectID = #FORM.ProjectID# AND PartsTaskID = #FORM.PartsTaskID#
    </CFQUERY>
    </CFLOOP>
  </cfif>

THE CODE SNIPPET ABOVE IS UNTESTED. PLEASE TEST PROPERLY BEFORE WORKING WITH REAL DATA

____________________________________
Just Imagine.
 
Well, I do believe that I have made myself a royal mess :)

Oh well a good learning experience right!

Please disregard the Form.bill_parts. It is just Form.billed.

"In your original code snippet you have only one checkbox named Form.bill_parts." - This is correct. I added a column to the table named billed. I thought the correct way to set this up would be to output the list of the taskIDs associated with that ProjectID, The checkbox would have a value of the Billed column. As the user checked the boxes it would carry over the particular task information to a "invoice page" and then on the backend update the table that the particular task has been billed.

"How many checkboxes will there be?" - There could be several

Are all of them going to be named bill_parts? - Really they all would be named billed. But yes, I thought that was the correct way to go.

John
 
Are all of them going to be named bill_parts? - Really they all would be named billed. But yes, I thought that was the correct way to go."

If all of the textboxes are named the same, how would you differentiate checkbox 1 from checkbox 5? The checkbox name (or something) must have some unique identifier allowing the UPDATE to take place correctly.

____________________________________
Just Imagine.
 
If all of the textboxes are named the same, how would you differentiate checkbox 1 from checkbox 5? The checkbox name (or something) must have some unique identifier allowing the UPDATE to take place correctly. " - That is exactly why I can't wrap my head around how checkboxes work. Mostly because I think I am trying to get them to work a certain and they don't.

The only think that I can differentiate would be the taskid.

John
 
Why not put the taskid in the value="" to differentiate one checkbox from another?

Something like:
Code:
1. <input name="billed" type="checkbox" value="#TaskID#" />...
2. <input name="billed" type="checkbox" value="#TaskID#" />...
3. <input name="billed" type="checkbox" value="#TaskID#" />...
4. <input name="billed" type="checkbox" value="#TaskID#" />...

<cfif isDefined("FORM.billed")>
 <cfloop list="#FORM.billed#" index="i">
    <cfquery name="Billing" datasource="intranet" dbtype="ODBC">
        UPDATE 	InventoryUsed
        SET 		billed ='Yes',
       		 			bill_date='#dateFormat(now())#'
				WHERE 	ProjectID = #FORM.ProjectID# AND PartsTaskID = #FORM.PartsTaskID# [b]AND TaskID = #i#[/b]
  	</cfquery>
 </cfloop>
</cfif>

____________________________________
Just Imagine.
 
Thank You. That did the trick. I think I understand now.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top