– Common Function Library Project

QueryStringDeleteVar(variable[, qs])

Last updated February 24, 2002


Nathan Dintenfass

Version: 1 | Requires: CF5 | Library: StrLib

Delete a variable (or a set of variables) and its value from a query string. By default, it uses the cgi.query_string, but you can pass in an optional second argument to replace the query string. This function is handy when you need to preserve an entire query string, but you want to kill off one of the variables. For example, if you have a button that appends "logout=yes" to the existing URL and you want to preserve that URL but no longer have the logout variable.

Return Values:
Returns a string.


<cfset qs = "arg1=1&arg2=2&arg3=3&arg4=4">


Name Description Required
variable A variable, or a list of variables, to delete from the query string. Yes
qs Query string to modify. Defaults to CGI.QUERY_STRING. No

Full UDF Source:

 * Deletes a var from a query string.
 * Idea for multiple args from Michael Stephenson (
 * @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 ( 
 * @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;
blog comments powered by Disqus


Latest Additions

Kevin Cotton added
May 5, 2016

Raymond Camden added
April 25, 2016

Chris Wigginton added
January 18, 2016

Gary Stanton added
November 19, 2015

Sebastiaan Naafs - van Dijk added
November 13, 2015

Created by Raymond Camden / Design by Justin Johnson