Simple variable passing isn't working

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • nassausky
    New Member
    • Mar 2007
    • 5

    Simple variable passing isn't working

    I acquired a very basic redirect script from:
    [HTML]http://www.minisitegal lery.com/blog/php-javascript-countdown-script-with-timezone-setting.html[/HTML]
    which is supposed to count down to a specified date and switch to a new webpage after that date. The original coder had included this quote with the code:


    WARNING…

    This script is not created with proper error trapping. If it’s not working, then something is wrong with your implementation. And I can’t provide support for it either. Oh yeah, it’s poorly documented to.

    So use at in anyway you want but don’t bug me with it.

    It uses PHP to acquire the date from the server and javascript to keep refreshing the live countdown timer. Ok the javascript counter works fine but the redirect isn't working.

    Code:
    document.location.href = "<?=$_GET['data']?>";
    alert("New Redirect Page="+ document.location.href);
    The output to this alert box showings the varbiable is equal to


    Then I click the OK button to the alert and for some reason it's substituting an odd redirect location as follows:



    Not sure why it is attaching both variables during runtime.
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    the php code seems strange, try
    [PHP]<?php echo $_GET['data']; ?>[/PHP]
    Last edited by Dormilich; Nov 18 '08, 09:31 PM. Reason: forgot [code] tags

    Comment

    • nassausky
      New Member
      • Mar 2007
      • 5

      #3
      Originally posted by Dormilich
      the php code seems strange, try
      [PHP]<?php echo $_GET['data']; ?>[/PHP]
      OK I tried that but it didn't work. It looks like the original coder intended on assigning the javascript variable document.locati on.href with the value being parsed from the input file. My javascript is weak and am I wrong to say that your method just prints out the text during runtime.

      Comment

      • acoder
        Recognized Expert MVP
        • Nov 2006
        • 16032

        #4
        $_GET['data'] would get the data parameter passed in the URL, e.g. for
        http://someurl/index.php?data= somesite/test.php, it would output "somesite/test.php". In JavaScript, the correct variable/object to set is window.location .href. Also, use full URLs to go to another site.

        Comment

        • nassausky
          New Member
          • Mar 2007
          • 5

          #5
          Thanks.. I understood both.. If you try out that simple script from the website you will see that it doesn't seem to work as you explained. I realize where it is getting the post data from and also have tried the full URLS and it still is keeping the old URL and appending the new URL as one string for some reason...

          Comment

          • acoder
            Recognized Expert MVP
            • Nov 2006
            • 16032

            #6
            OK, how are you calling this script?

            Comment

            • nassausky
              New Member
              • Mar 2007
              • 5

              #7
              I was calling it inside the body of the html file.

              Comment

              • acoder
                Recognized Expert MVP
                • Nov 2006
                • 16032

                #8
                No, I meant the actual code that you're using to call the script.

                Comment

                Working...