Solved

Parse brackets in the URL string

Posted on 2011-02-28
8
582 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
  • 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
 
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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

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…
SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
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…
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…

932 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now