/    Sign up×
Community /Pin to ProfileBookmark

a strange URL encoding

Hello guys

see if you can help me with this strange problem:
I have the following javascript function:

function changeNumberOfItems() {
var form = document.forms[0];
var [B]totalNumberOfItems[/B] = form.numItems.value;
[COLOR=green]alert(“”” + totalNumberOfItems + “””);[/COLOR]
totalNumberOfItems = totalNumberOfItems.replace(/^s+/,””);
totalNumberOfItems = totalNumberOfItems.replace(/s+$/,””);
[COLOR=green]alert(“”” + totalNumberOfItems + “””);[/COLOR]
form.action = “browsing.php?page=1&itemsPerPage=25&[B]numItems=” + totalNumberOfItems[/B];
[COLOR=green]alert(form.action);[/COLOR]
form.submit();
}

The value that I obtain from a form element (the bold one) comes from a textfield. I trim all whitespaces from around its value and the second alert shows me that indeed whitespaces have been removed.

The last alert shows me the URL encoding that the browser will request.
However, when the function executes, the actual URL that is displayed in the browser has an addtional + sign before the totalNumberOfItems value.
For example: instead of browsing.php?page=1&itemsPerPage=25&numItems=7
The URL in the address bar reads: browsing.php?page=1&itemsPerPage=25&numItems=[COLOR=red]+[/COLOR]7

Does anyone know what I am doing wrong?

thanks

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@David_HarrisonMar 26.2004 — I put you script into a page to test it out and I don't get that error at all. See for yourself, here is your code back again without the form submit at the end.

[upl-file uuid=a690fac2-c266-42df-bad7-9d0f8647b360 size=607B]form action test.zip[/upl-file]
×

Success!

Help @davidklonski spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...