#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2002
    Posts
    2
    Rep Power
    0

    Unhappy sending variables to new window using javascript


    I want to open a new window by clicking on a link on page_A and send a variable to the new page that has spaces. The following works for variables with no spaces

    echo "<a href=javascriptpenWin('displaytip.php?showtiptitle=$tiptitle')>$tiptitle</a>";

    if the variable has a space there is a message, "Unterminated String Constant" and will only pick up the first word of the variable.

    I have used this same code in PHP and it works fine as it picks up the spaces as %20 but I think javascript has some error with this, but I am sure there is a way - anyone know?
  2. #2
  3. mod_dev_shed
    Devshed Supreme Being (6500+ posts)

    Join Date
    Sep 2002
    Location
    Atlanta, GA
    Posts
    14,817
    Rep Power
    1100
    You might start by putting quotes around the href attribute.
    Code:
    echo "<a href=\"javascript;openWin('displaytip.php?showtiptitle=$tiptitle')\">$tiptitle</a>";
    Not sure if that will make any difference. If not, check out urlencode()
    # Jeremy

    Explain your problem instead of asking how to do what you decided was the solution.
  4. #3
  5. No Profile Picture
    Senior Citizen
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Jan 2001
    Location
    leftcoast
    Posts
    2,019
    Rep Power
    16
    Try this:

    function openWin(url) {
    url = escape(url);
    ......etc.
    }
  6. #4
  7. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2002
    Posts
    2
    Rep Power
    0

    Thumbs up Cheers from the HardMan!


    First one worked a treat! All I had to do is wrap the javascript href in the /" quotes /" as was suggested and it worked. Had spent an hour on it already trying to figure out where they went, but you saved me another hour of trying.

    The
    Hardman

IMN logo majestic logo threadwatch logo seochat tools logo