0

I need to check if two parameter names exists in the url. If any of them do i need to replace the value of the parameter.

I can match the parameter name, but i am not sure how to replace the value. The two parameters/values would be at the end of the url.

what i have so far is below.

url = “http://www.daniweb.com?parm1=value&parm2=value&parm3=value&parm4=value

// can i combine these some how?
var parm3RegExp = /parm3=/;
var parm4RegExp = /parm4=/;

// finds parm3. Now how can i replace the value?
url = parm3RegExp.exec(url)

I was thinking about something like below. but i want to replace the parameter value and not the name

var url = url.replace(/parm3=/, "");
1
Contributor
1
Reply
2
Views
11 Years
Discussion Span
Last Post by Sailor_Jerry
0

Got this to work.
I will just remove the parameters and the values if they are present in the url. Then run the logic to create and add the paramters and there values to the url, if they are needed.

url = “http://www.daniweb.com?parm1=value&parm2=value&parm3=value&parm4=value
var urlParm3loc = url.search(/&parm3=/);
var urlParm4loc = url.search(/&parm4=/);

if(urlParm3loc  > 0 || urlParm4loc > 0)
  {
	var startIndex = urlParm3loc > urlParm4loc  ? urlParm4loc  : urlParm3loc ;
	url = url.replace(url.substring(startIndex,url.length),"");
  }
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.