PDA

Click to See Complete Forum and Search --> : strings with spaces [Resolved]


ober0330
May 12th, 2004, 08:26 AM
Ok, so I have the following function:function gofull()
{
URL = location.href
if (URL.search("Date_Found") != -1)
{
URL = URL.substring(0,URL.search("Date_Found")-1)
}
URL=URL+"?Date_Found="+document.dform.Date_Found.value+"&Last_Known="+document.dform.Last_Known.value

if (document.dform.TagNum.options[document.dform.TagNum.selectedIndex].value != 1)
URL = URL+"&TagNum="+document.dform.TagNum.options[document.dform.TagNum.selectedIndex].value
if (document.dform.SYMP.value != "")
URL = URL+"&SYMP="+document.dform.SYMP.value
if (document.dform.User.options[document.dform.User.selectedIndex].value != 1)
URL = URL+"&user="+document.dform.User.options[document.dform.User.selectedIndex].value
if (document.dform.impact.value != "")
URL = URL+"&impact="+document.dform.impact.value

URL = URL+"&act_prod_date="+document.dform.act_prod_date.value
location.href = URL
}
-->
</script> It works great except for the fact that the "SYMP" field is a string that will contain spaces. When that field is put into the URL when the form is refreshed, it adds "%20" for each space... and then when I use the following: <?php
if(isset($_GET['SYMP']))
echo "<input type=text name=SYMP size=40 value=" . $_GET['SYMP'] . ">";
else
echo "<input type=text name=SYMP size=40 value=\"\">";
?> it only puts the first word of the string into the textbox.

How do I get it to grab the whole string out of the URL?

Acidic
May 12th, 2004, 08:33 AM
When SYMP is set, replace all spaces with another character, maybe dash.
SYMP.replace(" ", "-")

Then when PHP reads it, it can replace all dashes back to spaces.

ober0330
May 12th, 2004, 10:10 AM
That only seems to work for the first space.

ober0330
May 12th, 2004, 10:15 AM
Please tell me I don't have to resort to this:
http://www.breakingpar.com/bkp/home.nsf/Doc?OpenNavigator&U=45A5696524D222C387256AFB0013D850

Acidic
May 12th, 2004, 10:28 AM
only replaces first space???
How are you replacing them?

ober0330
May 12th, 2004, 10:36 AM
I was doing this:if (document.dform.SYMP.value != "")
URL = URL+"&SYMP="+document.dform.SYMP.value.replace(" ","-")

techgnome
May 12th, 2004, 10:39 AM
Look at the Server object, there should be a URLEncode and URLDencode functions. One changes the string to make it URL ready (adds the %20 where spaces are) and the other Dencodes if from URLEncoded back to regular string (the %20 turn back into spaces). Doing a replace space with - or _ while it works, it's not ideal, since a - or _ are (in theory) valid values in the string to begin with (wouldn't want a a space when it wasn't supposed to be there.

TG

Whoopse, just saw that this was PHP, the URLEncode and URLDencode still stand, they are functions built into PHP.

ober0330
May 12th, 2004, 10:42 AM
ok... nevermind. I'm an idiot. It was all in how I was feeding it back into the textbox. I don't have to do ANY kind of replacing. It does it automatically.