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 Andrzejek on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem turning checkbox on

Status
Not open for further replies.

LearnersPermit

Technical User
May 30, 2001
70
CA
I have a form that allows users to edit an item in an inventory system. The Checkbox is a problem - they can changed it to 0 without a problem, but when they change it to a 1 it fails. No error message is displayed.

<cfparam name="form.action" default="disp">


<cfif not isdefined("form.submit")>
<cfparam name="form.itemid" default="">
<cfparam name="form.description" default="">
<cfparam name="form.enabled" default="">

</cfif>

<!--- Set a local var for the itemid --->
<cfif ISDEFINED("form.itemid") AND form.itemid GT 0>
<cfif ISDEFINED("form.btnEdit")>
<cfset locitemid='#Trim(form.btnEdit)#'>
<cfelse>
<cfset locitemid='#form.itemid#'>
</cfif>
<cfelse>
<cfset locitemid="0">
</cfif>



<cfif ISDEFINED("form.smtDelete") AND locitemid GT 0>
<!--- Delete the Record --->
<cfquery name="qrydel" datasource="#request.dsn#" username="#request.uname#" password="#request.passwd#">
DELETE FROM tblStores
WHERE itemid = #locitemid#
</cfquery>

<cfset locPostMessage="Item Deleted Successfully">

<cfelseif ISDEFINED("form.smtSubmit") AND locitemid GT 0>
<!--- Edit the Item --->
<cfquery name="qryupdate" datasource="#request.dsn#" username="#request.uname#" password="#request.passwd#">
UPDATE tblStores
SET description = <cfqueryparam cfsqltype="cf_sql_varchar" value="#form.description#">,
unit = <cfqueryparam cfsqltype="cf_sql_varchar" value="#form.unit#">,
price = <cfqueryparam cfsqltype="cf_sql_real" value="#form.price#">,
catid = <cfqueryparam cfsqltype="cf_sql_integer" value="#form.catid#">,
supplierid = <cfqueryparam cfsqltype="cf_sql_integer" value="#form.supplierid#">,
other = <cfqueryparam cfsqltype="cf_sql_varchar" value="#form.other#">,
enabled = <cfif form.enabled neq ""><cfqueryparam cfsqltype="cf_sql_integer" value="#form.enabled#"><cfelse>0</cfif>
WHERE itemid = #locitemid#
</cfquery>

<cfset locPostMessage="The Item was Edited">
</cfif>

<cfquery name="qrecord" datasource="#request.dsn#" username="#request.uname#" password="#request.passwd#">
select tblStores.itemid,tblStores.description,tblStores.unit,tblStores.price,tblStores.catid,tblStores.supplierid,tblStores.other,tblStores.enabled,tblCategory.catid,tblCategory.category,tblSupplier.suppid,tblSupplier.supplier
from tblStores,
tblCategory,
tblSupplier
where itemid = '#locitemid#'
and tblStores.catid=tblCategory.catid
and tblStores.supplierid=tblSupplier.suppid
order by description
</cfquery>


<!---Get a Category--->
<cfquery name="qryCat" datasource="#request.dsn#" username="#request.uname#" password="#request.passwd#">
SELECT catid,category
FROM tblCategory
ORDER BY category ASC
</cfquery>

<!---Get a Supplier--->
<cfquery name="qrySupplier" datasource="#request.dsn#" username="#request.uname#" password="#request.passwd#">
SELECT suppid as supplierid,supplier
FROM tblSupplier
ORDER BY supplier ASC
</cfquery>


<cfif ISDEFINED("locPostMessage")>
<cfoutput><h3>#locPostMessage#</h3></cfoutput>
</cfif>


<cfif form.action eq "disp">
<html>
<head>
<title>"Stores Catalogue"</title>
<link rel="stylesheet" href="stores.css" type="text/css">

<br />

</head>
<body>
<table>
<tr>
<td width="25%" background="#E5E5E5;"></td>
<td width="75%">
<table cellpadding="10">
<tr><th>Edit an Item</th>
</tr>
<tr>
<td>
<pre>
<form name="editTime" action="#cgi.script_name#" method="post">
<cfoutput>

Item No.:
<input type="text" name="itemid" value="#qrecord.itemid#" size="60" maxlength="255">

Description:
<input type="text" name="description" value="#qrecord.description#" size="60" maxlength="255">

Price:
<input type="text" name="price" value="#qrecord.price#" size="60" maxlength="255">

Unit:
<input type="text" name="unit" value="#qrecord.unit#" size="60" maxlength="255">

Other:
<input type="text" name="other" value="#qrecord.other#" size="60" maxlength="255">

Available:
<input type="checkbox" name="enabled" value="#qrecord.enabled#"<cfif qrecord.enabled eq "1"> checked</cfif>>

</cfoutput>
<!---Category drop down box --->
Category:
<select name="catid">
<option value="#qryCat.category#">
</option>
<cfoutput query="qryCat">
<option value="#qryCat.catid#" <cfif qrecord.catid EQ qryCat.catid> selected</cfif>>#qryCat.category#</option></cfoutput></option>
</select>

<!---Supplier drop down box --->
Service:
<select name="supplierid">
<option value="#qrySupplier.supplier#">
</option>
<cfoutput query="qrySupplier">
<option value="#qrySupplier.supplierid#" <cfif qrecord.supplierid EQ qrySupplier.supplierid> selected</cfif>>#qrySupplier.supplier#</option></cfoutput></option>
</select>

</pre>
<input type="submit" value="Submit" name="smtSubmit">
<cfif locitemid GT 0>
<input type="Submit" value="Delete" name="smtDelete">
<input type="button" value="Cancel" onclick="location.href='edit_time.cfm'">
<cfelse>
<input type="Submit" value="Delete" name="" disabled>
<input type="button" value="Cancel" disabled>
</cfif>

</form>
</td>
</tr>
</table>
</table>
</cfif>
</body>
</html>
 
can't see your question

lines too long

please repeat question

use short sentences

like these

thanks

p.s. you have an H3 that comes ahead
of your HTML tag -- that's invalid

r937.com | rudy.ca
 
Thank you for looking at my problem.

I have a form that allows users to edit an item
in an inventory system.

The Checkbox is a problem -
users can change turn off enabled without a problem.
when enabled is turned on - it fails.
No error message is displayed.
 
you checkbox is passing a value equal to whatever the checkbox was set to before....


<input type="checkbox" name="enabled" value="#qrecord.enabled#"

if this is really an on/off switch, that value needs to be

<input type="checkbox" name="enabled" value="1"



Kevin

Phase 1: Read the CFML Reference
Phase 2: ???
Phase 3: Profit!
 
then this is a big waste also...

enabled = <cfif form.enabled neq ""><cfqueryparam cfsqltype="cf_sql_integer" value="#form.enabled#"><cfelse>0</cfif>

it should just be

enabled = <cfqueryparam cfsqltype="cf_sql_integer" value="#form.enabled#">

and then change your cfparam of form.enabled to default to 0.


and you set, do the same for the other checkboxes if there are more.

Kevin

Phase 1: Read the CFML Reference
Phase 2: ???
Phase 3: Profit!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top