Reputation: 1690
I have jQuery script that takes a URL parameter and adds the value to an input box.
When the URL is the form of www.mysite.com/page/?number=10
everything works fine. When the url includes .php
at the end of the page than the script doesn't work, e.g. www.mysite.com/page.php?number=10
.
I need for the script to work with .php
is used.
Here is the script:
jQuery(document).ready(function() {
(function($) {
jQuery.QueryString = (function(a) {
if (a == "") return {};
var b = {};
for (var i = 0; i < a.length; ++i)
{
var p=a[i].split('=');
if (p.length != 2) continue;
b[p[0]] = decodeURIComponent(p[1].replace(/+/g, " "));
}
return b;
})(window.location.search.substr(1).split('&'))
})(jQuery);
jQuery.QueryString["number"];
jQuery("#entry_2081224724").val(jQuery.QueryString["number"]);
});
Upvotes: 0
Views: 271
Reputation: 3985
Read this:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions
Your issue is, the regular expression character +
gives an instruction to repeat the character that precedes it one or more times. The syntax error your getting is telling you that you haven't given it a character to repeat.
Are you trying to replace all +
characters? If so, you're going to need to escape it with \
.
Are you trying to say "one or more /
characters"? Again, you'll need to escape that too, because /
denotes the beginning of a regular expression.
Upvotes: 1