Question
Trouble processing dynamically generated checkboxes
hello. this is my first time working with coldfusion for a
project. pardon me if i don't know anything remotely advanced.
the thing is this:
i'm trying to create a page in which i can use it to create an account with lecturer permissions. the user will be keying in the username, password. then there is this list of checkboxes for all the modules so that the user can check all the modules the owner of the lecturer account is teaching. this is so that the lecturer can only upload module material for modules that he or she is teaching.
upon submitting the page, the data source will then be updated by inserting multiple records according to the checkboxes checked. for example, i have 3 checkboxes, 1, 2, 3. i check box 1 and 3. when sent, the data source will store 2 data entries, userID=1/moduleID=1 and userID=1/moduleID=3.
but i can't get the processing of the checkboxes to work. here's the codes for both pages, addUSElect.cfm and addUSElect2.cfm
addUSElect.cfm
============
<!--get checkboxes--!>
<cfquery datasource="fypdatabase" name="moduleCHECKlist">
SELECT *
FROM moduleTABLE, courseTABLE
WHERE moduleTABLE.courseID = courseTABLE.courseID
ORDER BY courseTABLE.courseID
</cfquery>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" " http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns=" http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<form action="addUSElect2.cfm" method="post" name="FORM" id="FORM">
<table width="431" border="0" cellpadding="4" cellspacing="3">
<tr>
<td colspan="2" align="center"><strong>Create New Lecturer</strong></td>
</tr>
<tr>
<td width="140" align="right" valign="top">Username: </td>
<td width="266" valign="top"><label>
<input type="text" name="useTEXT" id="useTEXT" />
</label></td>
</tr>
<tr>
<td align="right" valign="top">Password: </td>
<td valign="top">
<input type="password" name="passTEXT" id="passTEXT" />
</td>
</tr>
<tr>
<td align="right" valign="top">Modules: <br />
(Select all that applies) </td>
<td align="left" valign="top"><table width="100%" border="0" cellpadding="0" cellspacing="0">
<cfloop query="moduleCHECKlist">
<tr>
<td width="21" align="left" valign="top">
<cfoutput>
<input type="checkbox" name="check" value="#moduleCHECKlist.moduleID#" />
</cfoutput>
</td>
<td width="165" align="left" valign="top">
<cfoutput>#moduleCHECKlist.moduleNAME# (#moduleCHECKlist.courseCODE#)</cfoutput>
</td>
</tr>
</cfloop>
</table></td>
</tr>
<tr>
<td colspan="2" align="center"><label>
<input type="submit" name="submit" id="submit" value="Create" />
</label></td>
</tr>
</table>
</form>
</body>
addUSElect2.cfm (i'm putting cfoutput yes and no to speed things up when testing whether the checking works)
=============
<!--to ensure that the number and order of loops is same as the list o checkboxes--!>
<cfquery datasource="fypdatabase" name="moduleCHECKlist">
SELECT *
FROM moduleTABLE, courseTABLE
WHERE moduleTABLE.courseID = courseTABLE.courseID
ORDER BY courseTABLE.courseID
</cfquery>
<cfloop query="moduleCHECKlist">
<cfif trim(check) IS "#moduleCHECKlist.moduleID#">
<cfoutput>Yes</cfoutput>
<cfelse>
<cfoutput>No</cfoutput>
</cfif>
</cfloop>
</html>
please help me in anyway you can to solve this conundrum.
the thing is this:
i'm trying to create a page in which i can use it to create an account with lecturer permissions. the user will be keying in the username, password. then there is this list of checkboxes for all the modules so that the user can check all the modules the owner of the lecturer account is teaching. this is so that the lecturer can only upload module material for modules that he or she is teaching.
upon submitting the page, the data source will then be updated by inserting multiple records according to the checkboxes checked. for example, i have 3 checkboxes, 1, 2, 3. i check box 1 and 3. when sent, the data source will store 2 data entries, userID=1/moduleID=1 and userID=1/moduleID=3.
but i can't get the processing of the checkboxes to work. here's the codes for both pages, addUSElect.cfm and addUSElect2.cfm
addUSElect.cfm
============
<!--get checkboxes--!>
<cfquery datasource="fypdatabase" name="moduleCHECKlist">
SELECT *
FROM moduleTABLE, courseTABLE
WHERE moduleTABLE.courseID = courseTABLE.courseID
ORDER BY courseTABLE.courseID
</cfquery>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" " http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns=" http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<form action="addUSElect2.cfm" method="post" name="FORM" id="FORM">
<table width="431" border="0" cellpadding="4" cellspacing="3">
<tr>
<td colspan="2" align="center"><strong>Create New Lecturer</strong></td>
</tr>
<tr>
<td width="140" align="right" valign="top">Username: </td>
<td width="266" valign="top"><label>
<input type="text" name="useTEXT" id="useTEXT" />
</label></td>
</tr>
<tr>
<td align="right" valign="top">Password: </td>
<td valign="top">
<input type="password" name="passTEXT" id="passTEXT" />
</td>
</tr>
<tr>
<td align="right" valign="top">Modules: <br />
(Select all that applies) </td>
<td align="left" valign="top"><table width="100%" border="0" cellpadding="0" cellspacing="0">
<cfloop query="moduleCHECKlist">
<tr>
<td width="21" align="left" valign="top">
<cfoutput>
<input type="checkbox" name="check" value="#moduleCHECKlist.moduleID#" />
</cfoutput>
</td>
<td width="165" align="left" valign="top">
<cfoutput>#moduleCHECKlist.moduleNAME# (#moduleCHECKlist.courseCODE#)</cfoutput>
</td>
</tr>
</cfloop>
</table></td>
</tr>
<tr>
<td colspan="2" align="center"><label>
<input type="submit" name="submit" id="submit" value="Create" />
</label></td>
</tr>
</table>
</form>
</body>
addUSElect2.cfm (i'm putting cfoutput yes and no to speed things up when testing whether the checking works)
=============
<!--to ensure that the number and order of loops is same as the list o checkboxes--!>
<cfquery datasource="fypdatabase" name="moduleCHECKlist">
SELECT *
FROM moduleTABLE, courseTABLE
WHERE moduleTABLE.courseID = courseTABLE.courseID
ORDER BY courseTABLE.courseID
</cfquery>
<cfloop query="moduleCHECKlist">
<cfif trim(check) IS "#moduleCHECKlist.moduleID#">
<cfoutput>Yes</cfoutput>
<cfelse>
<cfoutput>No</cfoutput>
</cfif>
</cfloop>
</html>
please help me in anyway you can to solve this conundrum.