?
Solved

Parse brackets in the URL string

Posted on 2011-02-28
8
Medium Priority
?
594 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 400 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
Stack Overflow Podcast - Frustrating Miracles

In this podcast, Stack Overflow interviewed Linux Academy CEO/Founder, Anthony James, and got his developer story!

"Follow your passion, be prepared to work hard and sacrifice, and, above all, don't let anyone limit your dreams."  - Donovan Bailey

 
LVL 39

Accepted Solution

by:
gdemaria earned 1600 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

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

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

Preface This article introduces an authentication and authorization system for a website.  It is understood by the author and the project contributors that there is no such thing as a "one size fits all" system.  That being said, there is a certa…
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…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).
Suggested Courses

770 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