Click to See Complete Forum and Search --> : a strange URL encoding


davidklonski
03-25-2004, 07:53 PM
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 totalNumberOfItems = form.numItems.value;
alert("\"" + totalNumberOfItems + "\"");
totalNumberOfItems = totalNumberOfItems.replace(/^\s+/,"");
totalNumberOfItems = totalNumberOfItems.replace(/\s+$/,"");
alert("\"" + totalNumberOfItems + "\"");
form.action = "browsing.php?page=1&itemsPerPage=25&numItems=" + totalNumberOfItems;
alert(form.action);
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=+7

Does anyone know what I am doing wrong?

thanks

David Harrison
03-25-2004, 08:54 PM
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.