Solved

Parse brackets in the URL string

Posted on 2011-02-28
8
592 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
Technology Partners: 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!

 
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

Suggested Solutions

CFGRID Custom Functionality Series -  Part 1 Hi Guys, I was once asked how it is possible to to add a hyperlink in the cfgrid and open the window to show the data. Now this is quite simple, I have to use the EXT JS library for this and I achiev…
I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

732 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