Skip to content

Instantly share code, notes, and snippets.

@Reyjay
Created April 21, 2014 17:45
Show Gist options
  • Save Reyjay/11150318 to your computer and use it in GitHub Desktop.
Save Reyjay/11150318 to your computer and use it in GitHub Desktop.
This code removes a variable from the URL and returns the string.http://cflib.org/udf/QueryStringDeleteVar
<cfscript>
/**
* Deletes a var from a query string.
* Idea for multiple args from Michael Stephenson ([email protected])
*
* @param variable A variable, or a list of variables, to delete from the query string.
* @param qs Query string to modify. Defaults to CGI.QUERY_STRING.
* @return Returns a string.
* @author Nathan Dintenfass ([email protected]@changemedia.com)
* @version 1.1, February 24, 2002
*/
function queryStringDeleteVar(variable){
//var to hold the final string
var string = "";
//vars for use in the loop, so we don't have to evaluate lists and arrays more than once
var ii = 1;
var thisVar = "";
var thisIndex = "";
var array = "";
//if there is a second argument, use that as the query string, otherwise default to cgi.query_string
var qs = cgi.query_string;
if(arrayLen(arguments) GT 1)
qs = arguments[2];
//put the query string into an array for easier looping
array = listToArray(qs,"&");
//now, loop over the array and rebuild the string
for(ii = 1; ii lte arrayLen(array); ii = ii + 1){
thisIndex = array[ii];
thisVar = listFirst(thisIndex,"=");
//if this is the var, edit it to the value, otherwise, just append
if(not listFind(variable,thisVar))
string = listAppend(string,thisIndex,"&");
}
//return the string
return string;
}
</cfscript>
Example:
<div id="containered" class="conteinerListsBox panel-collapse collapse" style="display:none;">
<a href="##" class="close closeMenu">close</a>
<ul id="listyles" class="lists">
<cfloop from="10" to="#attributeOption.recordCount#" index="attributeIndex">
<li class="selectListItem" id="#attributeOption.ATTRIBUTEVALUE[attributeIndex]#">
<a href="#productSmartList.buildURL('#filterPrefix##attributePath##attributeCode#=#URLEncodedFormat(attributeOption.attributeOptionValue[attributeIndex])#')#" <cfif productSmartList.isLikeFilterApplied(attributeCode, attributeOption.attributeOptionValue[attributeIndex]) or productSmartList.isFilterApplied(attributeCode, attributeOption.attributeOptionValue[attributeIndex])> class="checked"</cfif> id="object#attributeIndex#"><span class="checkboxImgUnchecked"></span>#attributeOption.attributeOptionLabel[attributeIndex]# ( #attributeOption.prodCount[attributeIndex]# )</a>
</li>
<cfif attributeIndex MOD 9 EQ 0>
</ul><ul id="listyles" class="lists">
</cfif>
</cfloop>
</ul>
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment