Results 1 to 8 of 8

Thread: strings with spaces [Resolved]

  1. #1

    Thread Starter
    Frenzied Member ober0330's Avatar
    Join Date
    Dec 2001
    Location
    OH, USA
    Posts
    1,945

    strings with spaces [Resolved]

    Ok, so I have the following function:
    Code:
    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 Code:
            <?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?
    Last edited by ober0330; May 12th, 2004 at 10:43 AM.
    format your code!! - [vbcode] [/vbcode]

    ANSWERS CAN BE FOUND HERE!!

    my personal company

  2. #2
    Frenzied Member Acidic's Avatar
    Join Date
    Sep 2003
    Location
    UK
    Posts
    1,090
    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.
    Have I helped you? Please Rate my posts.

  3. #3

    Thread Starter
    Frenzied Member ober0330's Avatar
    Join Date
    Dec 2001
    Location
    OH, USA
    Posts
    1,945
    That only seems to work for the first space.
    format your code!! - [vbcode] [/vbcode]

    ANSWERS CAN BE FOUND HERE!!

    my personal company

  4. #4

    Thread Starter
    Frenzied Member ober0330's Avatar
    Join Date
    Dec 2001
    Location
    OH, USA
    Posts
    1,945
    Please tell me I don't have to resort to this:
    http://www.breakingpar.com/bkp/home....256AFB0013D850
    format your code!! - [vbcode] [/vbcode]

    ANSWERS CAN BE FOUND HERE!!

    my personal company

  5. #5
    Frenzied Member Acidic's Avatar
    Join Date
    Sep 2003
    Location
    UK
    Posts
    1,090
    only replaces first space???
    How are you replacing them?
    Have I helped you? Please Rate my posts.

  6. #6

    Thread Starter
    Frenzied Member ober0330's Avatar
    Join Date
    Dec 2001
    Location
    OH, USA
    Posts
    1,945
    I was doing this:
    Code:
    if (document.dform.SYMP.value != "")
            URL = URL+"&SYMP="+document.dform.SYMP.value.replace(" ","-")
    format your code!! - [vbcode] [/vbcode]

    ANSWERS CAN BE FOUND HERE!!

    my personal company

  7. #7
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687
    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.
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  8. #8

    Thread Starter
    Frenzied Member ober0330's Avatar
    Join Date
    Dec 2001
    Location
    OH, USA
    Posts
    1,945
    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.
    format your code!! - [vbcode] [/vbcode]

    ANSWERS CAN BE FOUND HERE!!

    my personal company

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width