Using Checkboxes

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

    Using Checkboxes

    Hi,

    I've been mulling it over but I can't get my head around how to achieve the following:

    I have a page that displays jobs for a user. I'd like a checkbox which, when checked, removes jobs with the status of 'Completed', stays checked on the refresh of the page and then adds the Completed jobs when unchecked.

    Is this doable? I've tried this but I can't get it to work.

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

    #2
    How does the page refresh occur? By a submit or via JavaScript?

    What have you tried?

    Comment

    • ndeeley
      New Member
      • Mar 2007
      • 139

      #3
      I've added a field called 'Visible' to my table to use to unselect records from view. I've used a copy of the page to toggle between the two states of seeing / not seeing the records, which sort of works, but doesn't display the checkbox text propery. I'd like all the code to be on the one page.

      This is the code to select the records:

      Code:
      <cfif isDefined('mycheck')>
      
      <cfif mycheck EQ 1>
      
      <cfquery name="clearCompleted" datasource="taskbook">
      	update		tblTaskBooker
      	set			Invisible = 1
      	where		JobStatusFK = 'Completed' and AssignedToFK = '#username#'
      </cfquery>
      	
      <cfquery name="clearcheck" datasource="taskbook">
      update		tblStaff
      set			ClearC = 1 
      where		LoginName = '#username#'
      </cfquery>
      		
      </cfif>	
      
      <cfelse>
      </cfif>
      And this the checkbox code:
      Code:
      <form action="TB_ReviewGISA.cfm?mycheck=1" method="post">
      							
      							
      <cfif getAL.ClearC EQ 1>
      <input type="checkbox" name="clearC" value=1 checked="checked" onClick="this.form.submit();">
      Hide / Show completed tasks
      							
      <cfelse>
      							
      <input type="checkbox" name="clearC" value=1  onClick="this.form.submit();">
      Hide / Show completed tasks
      </cfif>
      </form>
      I use two pages, TBReviewGIS and TBReviewGISA.

      Comment

      • acoder
        Recognized Expert MVP
        • Nov 2006
        • 16032

        #4
        Is there a reason to update the database for hiding/showing? You could simply use a select statement to show only the records required.

        Also, you can combine the 2 into one page by using the cfelse part for the query which displays all records (when the checkbox is unchecked) or as I stated above, use the cfif within the select statement, e.g.
        Code:
        select ...
        where ...
        <cfif mycheck EQ 1>some where clause</cfif>
        One more thing: the checkbox display code could easily be combined into one piece:
        Code:
        <input type="checkbox" name="clearC" value=1
        <cfif getAL.ClearC EQ 1>checked="checked" </cfif>
        onClick="this.form.submit();">
        Hide / Show completed tasks

        Comment

        • ndeeley
          New Member
          • Mar 2007
          • 139

          #5
          Thanks acoder, I'll give it a go - hopefully I'll have no problems!

          Cheers
          Neil

          Comment

          Working...