Set your form to supply default values that are overridden or in the case of
a checkbox, have a hidden value with the same name that you strip in your
code. If only the hidden value exists, insert null otherwise, insert the
other list value. Multiple entries will usually be separated by a comma.

-----Original Message-----
From: Douglas Brown [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, July 02, 2002 2:07 PM
To: CF-Talk
Subject: Re: Working with empty lists


Ok...Let me try to be a little more presice in what I am needing, and by the
way Brian your help yesterday was excellent. What I want to do is insert the
value of "" or NULL if none of the checkboxes are checked and insert the id,
inventory_id into the table also. Right now if the person does not choose
any
options, then nothing gets inserted into the options table. This causes a
problem if the user later goes back and decides to give the car some options
from the update form since their is no inventory_id in the table to
reference
for the vehicle. Does this make a little more sense?






Douglas Brown
Email: [EMAIL PROTECTED]
----- Original Message -----
From: "Bryan Stevenson" <[EMAIL PROTECTED]>
To: "CF-Talk" <[EMAIL PROTECTED]>
Sent: Tuesday, July 02, 2002 1:52 PM
Subject: Re: Working with empty lists


> OK...I thought I showed you how to do this yesterday ;-)
>
> First off I think what you're trying to will loop as many times as there
are
options.  Instead you
> should only need to loop as many times as there are checked checkboxes.
yes
I know it's not a big
> deal, but if you can be more efficient...why not ;-)
>
> Here's what I'd do:
>
> DISPLAY AND ASSIGN VALUES TO CHECKBOXES:
>
> <cfloop query="get_otptions">
>   <input type="checkbox" name="chkOption" value="#ID#">#Option_Name#<br>
> </cfloop>
>
> AFTER THE BOXES ARE CHECKED AND THE FORM IS PASSED:
>
> Now we have to insert all your CHECKED options.  I'll just focus on the
option INSERT query and skip
> your other stuff to grab the right ID and all that (so at this point we
assume we have the vehicle
> ID).
>
> <cfquery datasource="DSN" name="InsertOptions">
>   <cfloop list="#FORM.chkOption#" index="Option_ID">
>     INSERT INTO
>       Options
>                 (
>                 inventory_id,
>                 option_id
>                 )
>                VALUES
>                (
>                #Inventory_ID#,
>                #Option_ID#
>                ) ;
>   </cfloop>
> </cfquery>
>
> So what happened above is;
> The value for FORM.chkOption will contain a comma delimited list of ALL
the
values (option_IDs) from
> the CHECKED boxes.  You CFLOOP through that list and insert the
Option_IDs.
>
> Hopefully I understand what you're up to and this has made sense ;-)
>
> Good luck
>
> Bryan Stevenson B.Comm.
> VP & Director of E-Commerce Development
> Electric Edge Systems Group Inc.
> t. 250.920.8830
> e. [EMAIL PROTECTED]
>
> ---------------------------------------------------------
> Macromedia Associate Partner
> www.macromedia.com
> ---------------------------------------------------------
> Vancouver Island ColdFusion Users Group
> Founder & Director
> www.cfug-vancouverisland.com
>
> ----- Original Message -----
> From: "Douglas Brown" <[EMAIL PROTECTED]>
> To: "CF-Talk" <[EMAIL PROTECTED]>
> Sent: Tuesday, July 02, 2002 1:08 PM
> Subject: Re: Working with empty lists
>
>
> > Ok here we go.
> >
> > I am using the hidden field as someone pointed out
> >
> > IE:
> > <input type="hidden" name="chkOptionList"
value="#valuelist(get_options.id)#">
> > This gives me a list of 1,2,3,4,5 etc...etc...
> >
> > then using the <cfif listFind(attributes.chkOption,j)> to see if the
checkbox
> > was indeed checked and if so run the query to insert the value and if
not
to
> > insert "NULL" or ""
> >
> >
> >
> >
> >
> > Douglas Brown
> > Email: [EMAIL PROTECTED]
> > ----- Original Message -----
> > From: "Bryan Stevenson" <[EMAIL PROTECTED]>
> > To: "CF-Talk" <[EMAIL PROTECTED]>
> > Sent: Tuesday, July 02, 2002 1:04 PM
> > Subject: Re: Working with empty lists
> >
> >
> > > An overview of exactly what you're trying to do might help.  It's hard
to
> > tell where everything is
> > > coming from and what kind of value it's supposed to have ;-)
> > >
> > > Bryan Stevenson B.Comm.
> > > VP & Director of E-Commerce Development
> > > Electric Edge Systems Group Inc.
> > > t. 250.920.8830
> > > e. [EMAIL PROTECTED]
> > >
> > > ---------------------------------------------------------
> > > Macromedia Associate Partner
> > > www.macromedia.com
> > > ---------------------------------------------------------
> > > Vancouver Island ColdFusion Users Group
> > > Founder & Director
> > > www.cfug-vancouverisland.com
> > >
> > > ----- Original Message -----
> > > From: "Douglas Brown" <[EMAIL PROTECTED]>
> > > To: "CF-Talk" <[EMAIL PROTECTED]>
> > > Sent: Tuesday, July 02, 2002 12:55 PM
> > > Subject: Re: Working with empty lists
> > >
> > >
> > > > I still must be doing something wrong.....It inserts all the values
of
the
> > > > checkboxes, if they are checked or not.
> > > >
> > > > Here is the code I have so far, and thanks for all the help
> > > >
> > > > <cfif ListLen(attributes.chkOptionList)>
> > > >     <cfloop list="#attributes.chkOptionList#" index="j">
> > > >     <cfparam name="attributes.chkOption" type="string"
default="NULL">
> > > >     <cfif ListFind(attributes.chkOption,j)>
> > > >    <cfquery datasource="#request.site.dsn#" name="insert_options">
> > > >    DECLARE  @maxid int
> > > >    BEGIN
> > > >     SELECT  @maxid = MAX(ID)
> > > >     FROM   options
> > > >     IF    @maxid IS NULL
> > > >     SELECT   @maxid = 1
> > > >     ELSE
> > > >     SELECT   @maxid = @maxid + 1
> > > >    END
> > > >
> > > >    DECLARE  @max_inv_id int
> > > >    BEGIN
> > > >     SELECT  @max_inv_id = MAX(ID)
> > > >     FROM   inventory
> > > >    END
> > > >    INSERT INTO options ( id,
> > > >          inventory_id,
> > > >          option_id )
> > > >
> > > >    VALUES    ( @maxid,
> > > >           @max_inv_id,
> > > >          #j# )
> > > >    </cfquery>
> > > >    </cfif>
> > > >   </cfloop>
> > > >  </cfif>
> > > >
> > > >
> > > >
> > > >
> > > > Douglas Brown
> > > > Email: [EMAIL PROTECTED]
> > > > ----- Original Message -----
> > > > From: "S. Isaac Dealey" <[EMAIL PROTECTED]>
> > > > To: "CF-Talk" <[EMAIL PROTECTED]>
> > > > Sent: Tuesday, July 02, 2002 11:27 AM
> > > > Subject: Re: Working with empty lists
> > > >
> > > >
> > > > > > I always CFPARAM the checkbox var to blank (default="").  Then I
add a
> > > > > > case statement to where I'm
> > > > > > going to add it;
> > > > > >
> > > > > > <cfif NOT len(MyCheckboxVar)>
> > > > > >   NULL,
> > > > > > <cfelse>
> > > > > >   #MyCheckboxVar#
> > > > > > </cfif>
> > > > > >
> > > > > > I think your method evaluates attributes.chkOption to a string
of
NULL
> > and
> > > > > > not a NULL value ;-)
> > > > >
> > > > > I'm usually able to default these sorts of items to a string of
"NULL"
> > in
> > > > > the cfparam tag, i.e.
> > > > >
> > > > > <cfparam name="attributes.#j#" type="numeric" default="NULL">
> > > > >
> > > > > since you don't put quotes around either a NULL or a numeric value
in
> > the
> > > > > query, this shouldn't produce any syntactical problems, however,
from
> > the
> > > > > code given in the previous email it doesn't look like you're
getting
all
> > the
> > > > > records you want to insert...
> > > > >
> > > > > My best guess would be to use the same query which generates the
list of
> > > > > checkboxes on the form page further up in your action page, then
loop
> > > > > through that query and default all those checkboxes to null... or
you
> > could
> > > > > use a hidden form field on the form page to give you the list of
> > checkboxes
> > > > > to loop over, since using #attributes.chkOption# is probably only
giving
> > you
> > > > > the checkboxes which have been checked on the form page... so if
you
> > used
> > > > >
> > > > > <input type="hidden" name="chkOptionList"
> > > > > value="#valuelist(myquery.chkOption)#>
> > > > >
> > > > > in your form and #attributes.chkOptionList# as the list in your
> > <cfloop>,
> > > > > then you can check for options that weren't checked on the form
with
> > > > > #ListFind(form.chkOption,j)# ... If the result is anything other
than 0
> > the
> > > > > user checked the box.
> > > > >
> > > > > hth
> > > > >
> > > > > Isaac Dealey
> > > > > www.turnkey.to
> > > > > 954-776-0046
> > > > >
> > > >
> > >
> >
> 

______________________________________________________________________
This list and all House of Fusion resources hosted by CFHosting.com. The place for 
dependable ColdFusion Hosting.
FAQ: http://www.thenetprofits.co.uk/coldfusion/faq
Archives: http://www.mail-archive.com/cf-talk@houseoffusion.com/
Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists

Reply via email to