Solved

Parse brackets in the URL string

Posted on 2011-02-28
8
593 Views
Last Modified: 2012-05-11
Hi,

I was trying to figure out how to parse brackets in the URL string. I have a javascript program that serializes my data and passes the following URL string to my coldfusion page

http://hsecfs1/developmentdmz/mctr/sortAjax.cfm?item[]=1&item[]=2&item[]=3

Unfortunatley, I can't figure out how to pull the data.

<cfoutput>#url.item[]#</cfoutput> doesn't seem to work. Any advice would be appreciated. Thank you!
0
Comment
Question by:jsimonuchc
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 2
8 Comments
 
LVL 3

Assisted Solution

by:dagaz_de
dagaz_de earned 100 total points
ID: 34998797
can you leave the brackets away, i think it wont work with brackets. Without you will get a comma separated list. Then you can loop over the list to get the values....

?item=1&item=2&item=3

then
<cfoutput>#url.item#</cfoutput>

<cfloop list="#url.item#" index="i">

     <!--- Do something with i --->
    <cfoutput>#i#</cfoutput>
<cfloop>
0
 
LVL 3

Expert Comment

by:dagaz_de
ID: 34998808
Sorry the cfloop was not closed correct:

<cfoutput>#url.item#</cfoutput>

<cfloop list="#url.item#" index="i">

     <!--- Do something with i --->
    <cfoutput>#i#</cfoutput>
</cfloop>
0
 
LVL 1

Author Comment

by:jsimonuchc
ID: 34998830
No, I cannot remove the brackets (or I haven't figured out how to do it yet).
0
Why You Need a DevOps Toolchain

IT needs to deliver services with more agility and velocity. IT must roll out application features and innovations faster to keep up with customer demands, which is where a DevOps toolchain steps in. View the infographic to see why you need a DevOps toolchain.

 
LVL 39

Accepted Solution

by:
gdemaria earned 400 total points
ID: 34998843
wow, that's unique.

How about  <cfset theValue = url["item[]"]>

You could also dump the url to see what's in there

<cfdump var="#url#">


The result, if you can read it, is a comma delimited list of values in one variable:  1,2,3  because the same name is used in each.
0
 
LVL 1

Author Comment

by:jsimonuchc
ID: 34998861
CFDUMP shows me a struct with the following contents:

ITEM[]       1,2,3
0
 
LVL 1

Author Comment

by:jsimonuchc
ID: 34998869
Awesome,  <cfset theValue = url["item[]"]> seems to work.
It gives me the values in a comma separated list.
0
 
LVL 39

Expert Comment

by:gdemaria
ID: 34998885

perfect, glad it works
0
 
LVL 3

Expert Comment

by:dagaz_de
ID: 34998988
now you can loop over the list like i told you....

<cfset theValue = url["item[]"]>

<cfloop list="#theValue#" index="i">

     <!--- Do something with i --->
    <cfoutput>#i#</cfoutput>
</cfloop>
      
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I spent nearly three days trying to figure out how incorporate OAuth in Coldfusion for the Eventful API. Hopefully, this article will allow Coldfusion Programmers to buzz through the API when they need to. Basically, what this script does is authori…
Shoutout to Emily Plummer (http://www.experts-exchange.com/members/eplummer26.html) for giving me this article! She did most of it, I just finished it up and posted it for her :)    Introduction In a previous article (http://www.experts-exchang…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question