Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 254
  • Last Modified:

Dynamically created checkboxes

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
LoneWolf_CSU
Asked:
LoneWolf_CSU
1 Solution
 
jonnygo55Commented:
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
 
Renante EnteraCommented:
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
 
anandkpCommented:
the above example shld help u have an idea, on how to proceed.

let us know what ur code looks like !
0
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
substandCommented:
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
 
James RodgersWeb Applications DeveloperCommented:
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
 
LoneWolf_CSUAuthor Commented:
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

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now