All you need to do is use a '|' character as the delimiter in the option
box. Like this:

<select name="modelname">
<option id="23" value="P123|23">P123</option>
</select>

Then on the action page, if you were allowing multiple selections you would
end up with a list like this:

P123|23,P124|24

Which you can loop over using the comma as the record delimiter and then
inside the loop break out the first and last value using the pipe char (|)
as the delimiter. All CFML list functions accept a delimiter.

Here is a working example:

<!--- this is the value passed from the form --->
<cfset form.modelname="P123|23,P124|24">

<cfoutput>
You selected #listlen(form.modelname)# items.
<BR><BR>
</cfoutput>

<cfset count=0>
<cfloop list="#form.modelname#" index="item">
         <cfset count=count+1>
         <!--- get the ID and name for each item using the pipe char
delimiter--->
         <cfset itemID=listLast(item,'|')>
         <cfset itemName=listFirst(item,'|')>

                 <cfoutput>
                                 Item #count# ID:#itemID#<BR>
                         Item #count# Name:#itemName#<BR>
                         <BR><BR>
                 </cfoutput>
</cfloop>

Brook Davies
logiforms.com

At 04:32 PM 2/9/2004, you wrote:
>One small detail that I forgot about. The portion of the page that has the
>select is being looped over. So, I could have multiple select boxes with
>the name of modelname.
>
><select name="modelname">
><option id="23" value="P123,23">P123</option>
></select>
><select name="modelname">
><option id="24" value="P124,24">P124</option>
></select>
>
>My list then becomes P123,23,P124,24 etc...
>
>On the next page I need to loop over that list to pull information from
>the db based on the first part (p123, p124). Would I still be able to do
>it this way? Or should I check into some kind of _javascript_?
>
>Thanks
>
> > Kelly,
> >
> > You do not need the listlen(). That function just counts and returns the
> > number of items in a list. So what you have here would likely return '1'.
> > The inner function is correct. Try putting this on the forms action page
> > so
> > you can see whats happening.
> >
> >
> > <cfoutput>
> > The value from the form is: #form.modelnumber# <BR>
> > The  first item in the list is:#Listfirst(form.modelnumber)#<BR>
> > The  second item in the list is:#listLast(form.modelnumber)#<BR>
> > </cfouptut>
> >
> > Note, when you do this, #ListLen(Listfirst(form.modelnumber))#, you are
> > first (the inner function first) getting the first item in the list and
> > then (the outer function) counting the number of items in the list, which
> > is 1, the result of the inner function.
> >
> > Brook
> >
> >
> >
> > At 04:02 PM 2/9/2004, you wrote:
> >>I am looping over the list on the next page, but now it needs to be on
> >> the
> >>first item in the list...what is the correct syntax to do that:
> >>
> >>#ListLen(Listfirst(form.modelnumber))#  ??
> >>
> >> > ----- Original Message -----
> >> > From: <[EMAIL PROTECTED]>
> >> > To: "CF-Talk" <[EMAIL PROTECTED]>
> >> > Sent: Monday, February 09, 2004 4:07 PM
> >> > Subject: OT: option id
> >> >
> >> >
> >> >> Can anyone tell me how to get the value of an option id?
> >> >>
> >> >> Example:
> >> >> <select name="modelname">
> >> >> <option id="23" value="Pl23">P123</option>
> >> >> </select>
> >> >>
> >> >> Of course, when I output modelname on the next page I get the value,
> >> put
> >> >> I
> >> >> also need to get the id. Is this possible?
> >> >
> >> > You won't be able to get the ID on the form's action page.
> >> >
> >> > easiest thing to do would be append it to the value creating a comma
> >> > delimited list:
> >> >
> >> > <select name="modelname">
> >> >      <option id="23" value="P123,23">P123</option>
> >> > </select>
> >> >
> >> > now on the action page you can do:
> >> >
> >> > ID: #listLast(form.modelname)#
> >> > Value: #listFirst(form.modelname)#
> >> >
> >> > other alternative would be to populate a hidden field via _javascript_
> >> using
> >> > the onchange event handler in the <select> tag.
> >> >
> >> > Charlie
> >> >
> >> >
> >> >
> >> >
> >>
> >>----------
> >>[
> >
>
>----------
>[
[Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings]

Reply via email to