Solved

Dynamically created checkboxes

Posted on 2003-11-06
6
245 Views
Last Modified: 2013-12-24
I'm creating a web-based program that manages the library (books and videos) for the office I work in and have run into a small problem.

On the checkin page, I have a cfselect box that lists all the students that currently have materials checked out.  When a student's name is selected, the page automatically reloads and shows, in addition to the cfselect box with the student's name, a list of materials that they currently have checked out.  Each item in the list has a checkbox next to it.

I'd like to be able to check the boxes next to each item that the student is returning, so that they can all be checked in in one pass.  The problem I'm having, though, is that I can't figure out how to dynamically assign "values" to the checkboxes so that they can be processed by the scripting on the action page.  Any ideas?

BTW, for the time being, I've implemented a page that allows me to check in materials one item at a time, so it's not like the entire project is going to bomb if I can't get this one feature working...but it would be a much appreciated feature by the members of our office staff.  So any help recieved would be equally appreciated.

--
Dave "LoneWolf" Savitsky
LoneWofl_CSU@hotmail.com
0
Comment
Question by:LoneWolf_CSU
6 Comments
 
LVL 2

Accepted Solution

by:
jonnygo55 earned 200 total points
ID: 9696109
shouldnt be too hard...just have to understand what you are currently doing...

sounds like you are already outputting the checked out items...not sure why you cant assign a value to it though...

<cfoutput query="checkedItems">
  <input type="checkbox" name="checkedIn" value="#checkedItems.itemID#" checked>#itemName#<br>
</cfoutput>

something like that should give you a list of all items being checked in...
 
on your processing page you could loop through the checkedIn variable and process however you like

<cfloop list="#checkedIn#" index="thisItem">
    ...do something with each #thisItem#...
</cfloop>
0
 
LVL 14

Expert Comment

by:Renante Entera
ID: 9698049
You can have something like this :

On you checkin page :

<cfquery name="GetNames" datasource="dsn">
SELECT name FROM TableName
</cfquery>

<cfif IsDefined('nameselected')>
<cfquery name="GetMaterials" datasource="dsn">
SELECT name,material FROM TableMaterial
WHERE name = "#nameselected#"
</cfquery>
</cfif>

<form name="form1" action="process.cfm" method="post">
  Select Name of Student :
  <select name="selectedname" onchange="document.location='checkinpage.cfm?nameselected=<cfoutput>#form.selectedname#</cfoutput>'">
  <option></option>
  <cfoutput query="GetNames">
    <option value="#name#">#name#</option>
  </cfoutput>
  </select>
  <cfif IsDefined('nameselected')>
  <cfoutput query="GetMaterials">
    #material# <input type="checkbox" name="checkedIn" value="#material#">
  </cfoutput>
  </cfif>
</form>

Then on your process.cfm, you may now refer to the checkbox values:

<cfif IsDefined('form.checkedIn')>
  <cfloop list="#form.checkedIn#" index="material" delimiters=",">
    <cfoutput>#material#</cfoutput> <!--- You may now refer to this value --->
  </cfloop>
</cfif>

Goodluck!
eNTRANCE2002 :-)
0
 
LVL 17

Expert Comment

by:anandkp
ID: 9699063
the above example shld help u have an idea, on how to proceed.

let us know what ur code looks like !
0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 10

Expert Comment

by:substand
ID: 9699341
you should name all the checkboxes the same name and assign valuies as the id like jonnygo55 sugguested.  then, say you name that <input name="boxes"..> then you just need to process in the action page:

<cfif isdefined("form.boxes")>
    <cfloop list="#form.boxes#" index="item">
             perform action on #item#
    </cfloop>
</cfif>
0
 
LVL 25

Expert Comment

by:James Rodgers
ID: 9701253
in this example empstatus is the name of the check box from the form page where the checkboxes were generated dynamically and named empstatus#currentrow# and given a true value as the query was output

recordcount is set in the form page and is the number of records being submitted in the form

this will check to see if the checkbox was checked and enter the necessary info into a database

<cfloop index="idx" from="1" to="#form.RECCOUNT#">
<cfquery name="setEmpStatus" datasource="" password="" username="">
<cfif isdefined('form.empstatus#idx#')>
<cfset EMPID =  #evaluate('form.empid#idx#')#>
<cfset TRN =  #evaluate('form.empStatus#idx#')#>
INSERT INTO TRNG_EXEMPTION_LIST VALUES ('#EMPID#' , '#TRN#');    
</cfif>
</cfquery>
</cfloop>
0
 

Author Comment

by:LoneWolf_CSU
ID: 9741714
Thanks, all for your help.  I can't believe how easy the solution really was...dunno why it never crossed my mind.

I never did get the automatic refresh working properly...I'm going to continue to work on it, but for the time being I just put a secondary page in there.

Thanks again.

--
Dave "LoneWolf" Savitsky
LoneWolf_CSU@hotmail.com
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Most ColdFusion developers get confused between the CFSet, Duplicate, and Structcopy methods of copying a Structure, especially which one to use when. This Article will explain the differences in the approaches with examples; therefore, after readin…
When it comes to showing a 404 error page to your visitors, you do not want that generic page to show, and you especially do not want your hosting provider’s ad error page to show either. In this article, I will show you how to enable the custom 40…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now