skip to main |
skip to sidebar
RSS Feeds
ASP.NET, JavaScript, Oracle and SQL articles and code.
ASP.NET, JavaScript, Oracle and SQL articles and code.
11:09 AM
Posted by Michael Heliso
Note: Please check JavaScript Utility Functions Note.
The following function will allow you to change the value of a specified parameter from the URL. You just have to pass the parameter name and desired parameter value.
/*Define the namespaces*/
var JavaScript = {};
JavaScript.Utils = {};
JavaScript.Utils.URL = {};
JavaScript.Utils.URL.ReplaceUrlParam = function(name, value) {
name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
var regexS = "[\\?&]" + name + "=([^&#]*)";
var regex = new RegExp(regexS);
var results = regex.exec(window.location.href);
if (results == null)
return false;
else {
var form = document.forms[0];
if (form) {
form.action = form.action.replace(results[0], results[0].replace(/=(.*)/, '=' + value));
}
}
};