www.webdeveloper.com
Results 1 to 4 of 4

Thread: how can I use dynamic GET variables?

  1. #1
    Join Date
    Apr 2011
    Posts
    6

    how can I use dynamic GET variables?

    Hi CF people,

    I created the following GET String with Javascript:


    Code:
    verarbeite.cfm?anzahl=5&id_3=12&menge_3=25&id_5=2&menge_5=100
    this is how I did it:

    Code:
    Pseudocode:
    var sendStr='?anzahl='+anzahl;
    for(i=1 to anzahl)
    {
      if(mengeID>0){
        sendStr=sendStr+'&id_'+i+'='+ID+'&menge_'+i+'='+mengeID;
      }
    }
    req4.open('get', 'verarbeite.cfm'+sendStr);

    now I want to access with my "verarbeite.cfm" the single menge variables

    Code:
    <cfif IsDefined("anzahl")>
    	
    	<cfloop 
    	  index = "loopCount"
    	  from = "1"
    	  to = #anzahl#
    	  step = "1">
    		
    		#menge_&loopCount#  
    	</cfloop>
    </cfif>
    but how can I call menge_3, menge_5???
    how do I get the connection beetween menge_ and loopCount??

    Thanks
    JollyRoger

  2. #2
    Join Date
    Dec 2002
    Location
    St. Louis, MO, USA
    Posts
    1,582
    URL parameters can be accessed with url.[whatever]
    Code:
    <cfif isDefined("url.anzahl")>
       <cfset local.anzahl = url.anzahl>
    </cfif>
    If you want to set local variables for ALL URL parameters, make sure your parameter values are URLEncoded (escaped):
    Code:
    <cfif len(trim(cgi.query_string)) gt 0>
       <cfloop index="idx" list="#cgi.query_string#" delimiters="&">
            <cfset local.thisName = getToken(idx,1,"=")>
            <cfset local.thisValue = URLDecode(getToken(idx,2,"="))>
            <cfset "local.#local.thisName#" = trim(local.thisValue)>
       </cfloop>
       <cfdump var="#local#">
    </cfif>
    Untested, but it should work.

  3. #3
    Join Date
    Apr 2011
    Posts
    6
    sorry for my late answer, but it works perfect. thanks!

  4. #4
    Yes, that seems should work perfect , thank you .

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles