SitePoint Sponsor

User Tag List

Results 1 to 14 of 14
  1. #1
    Mad Beach Bum jgsketch's Avatar
    Join Date
    Aug 2002
    Location
    FL
    Posts
    825
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Script not redirecting when trying to encode URL

    I have a thank you page where I'm redirecting user after 5 seconds to another page. This part of the script seems to work fine and redirects to the URL I want. However, the issue comes when I try and add parameters onto the URL. The redirect will stop working. I believe it's a formatting issue, as I've used the code in a different application. I've tried using different approaches to the punctuation but that did not help.

    Could someone take a quick look at the code below and let me know if I have a mistake in the formatting? Thanks.

    Code:
    <script type="text/javascript">
    <!--
    function delayer(){
        window.location = 'http://www.xxx.com/click.track?CID=123&AFID=123&type=xxx&SID=ThankYou&fname='  + escape(document.getElementById('firstname').value) + '&lname=' + escape(document.getElementById('lastname').value) + '&email=' + escape(document.getElementById('email').value) + '&state=' + escape(document.getElementById('state').value);
    }
    //-->
    </script>
    
    </head>
    <body bgcolor="#C0C0C0"  onLoad="setTimeout('delayer()', 5000)">

  2. #2
    SitePoint Wizard
    Join Date
    Dec 2003
    Location
    USA
    Posts
    2,582
    Mentioned
    29 Post(s)
    Tagged
    0 Thread(s)
    Do you get any Javascript errors when it tries to redirect?

    Does it work if you do really simple values (no punctuation)?

    Also you might try window.location.href instead and see if that gives you any difference (sorry I can't test for you right now).

  3. #3
    Mad Beach Bum jgsketch's Avatar
    Join Date
    Aug 2002
    Location
    FL
    Posts
    825
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I do not get any errors, the page just sits there. I did try using simple values for testing purposes. As long as there is nothing after the last quotation mark for the URL, it will redirect. So code code below will work:
    Code:
    function delayer(){
        window.location = 'http://www.xxx.com/click.track?CID=123&AFID=123&type=xxx&SID=ThankYou&fname=sample'
    }
    But I would not be able to pass all of my values to the other page.

    I also tried the href code, but that did not work.

    Thanks for your help.

  4. #4
    SitePoint Wizard
    Join Date
    Dec 2003
    Location
    USA
    Posts
    2,582
    Mentioned
    29 Post(s)
    Tagged
    0 Thread(s)
    Try taking the value you are trying to pass to window.location and alert it so you can see exactly what it works out to be. It may be that something isn't going as you planned.

  5. #5
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,526
    Mentioned
    83 Post(s)
    Tagged
    3 Thread(s)
    Quote Originally Posted by jgsketch View Post
    I have a thank you page where I'm redirecting user after 5 seconds to another page. This part of the script seems to work fine and redirects to the URL I want. However, the issue comes when I try and add parameters onto the URL. The redirect will stop working. I believe it's a formatting issue, as I've used the code in a different application. I've tried using different approaches to the punctuation but that did not help.

    Could someone take a quick look at the code below and let me know if I have a mistake in the formatting? Thanks.

    Code:
    <script type="text/javascript">
    <!--
    function delayer(){
        window.location = 'http://www.xxx.com/click.track?CID=123&AFID=123&type=xxx&SID=ThankYou&fname='  + escape(document.getElementById('firstname').value) + '&lname=' + escape(document.getElementById('lastname').value) + '&email=' + escape(document.getElementById('email').value) + '&state=' + escape(document.getElementById('state').value);
    }
    //-->
    </script>
    
    </head>
    <body bgcolor="#C0C0C0"  onLoad="setTimeout('delayer()', 5000)">
    Your code works for me, when the page contains form fields with identifiers that match.

    So, the next stage of investigation is for us to look at a test page of yours that exhibits the problem, so that we can find out if there's something else causing things to go awry.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  6. #6
    Mad Beach Bum jgsketch's Avatar
    Join Date
    Aug 2002
    Location
    FL
    Posts
    825
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for testing. I'm surprised it worked for you. My thank you page is a barebones page with only one other script running. It's a small javascript for a privacy popup. I tried deleting this script for a test, but still could not get it to work. I also tested to make sure the sessions variable were being passed by printing them to the page. That seemed to be fine.

    Here is the code:
    HTML Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <HTML>
    <HEAD>
    <TITLE>Thank You</TITLE>
    
    <SCRIPT LANGUAGE="JavaScript">
    function popUp(URL) {
    day = new Date();
    id = day.getTime();
    eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width=250,height=300,left = 462,top = 359');");
    }
    </SCRIPT>
    
    <SCRIPTtype="text/javascript">
    <!--
    function delayer(){
        window.location = 'http://www.xxx.com/click.track?CID=123&AFID=123&type=xxx&SID=ThankYou&fname='  + escape(document.getElementById('firstname').value) + '&lname=' + escape(document.getElementById('lastname').value) + '&email=' + escape(document.getElementById('email').value) + '&state=' + escape(document.getElementById('state').value);
    }
    //-->
    </SCRIPT>
    
    </head>
    <body bgcolor="#C0C0C0"  onLoad="setTimeout('delayer()', 5000)">
    
    <table width="900" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF">
    <TR>
        <TD align="left" valign="top">
            <TABLE border="0" cellpadding="0" cellspacing="0" width="100%">
                <TR>
                    <TD style="background-color: #0536A0;" align="center">
                        <DIV style="width: 480px; height: 80px; overflow: hidden;"><IMG src="http://www.xxx.com/images/logo.gif" width="480" height="100" />
                        </DIV>
                    </TD>
                </TR>
            </TABLE>
            <TABLE id="Table1" cellSpacing="0" cellPadding="1" width="900" align="center" border="0" style="FONT-SIZE: 11pt; FONT-FAMILY: Trebuchet MS">
                <TR>
                    <TD colspan="3">
                       <P align="center">Thank You. Your request has been   received.<BR> A representative will contact you.</P>
                       <P align="center"><STRONG><FONT size="4">You will be redirected to USAFreeScores in a moment!</FONT></STRONG><BR>
                       <font color="#0536A0"><%= Session("firstname") %></font><BR></P>
                       <P align="center">
                       <BR><BR><a href="javascript:popUp('privacy-popup.htm')" style="color:blue;"><strong style="color:blue;">Privacy Policy</strong></a>
                       <BR>
                    </TD>
                </TR>
                <TR>
                    <TD colspan="3">
                    <BR><P align="center"><a href="http://www.xxx.com">Click Here</a> to return to the Home Page.
                    </TD>        
                </TR>
                <TR>
                    <TD align="center" colspan="3">
                    <A target="_Blank" href="http://www.bbbsoutheastflorida.org/"><img alt="BBB Online" border="0" src="http://www.xxx.com/images/bbblogo.jpg" /></A>               
                    <A target="_Blank" href="http://www.nifce.org/"><img alt="National Association of Certified Credit Counselors "  border="0" src="http://www.xxx.com/images/naccclogo.gif" /></A>
                    <A target="_Blank" href="http://www.aadmo.org/"><img alt="American Association of Debt Management Organizations" border="0" src="http://www.xxx.com/images/aadmologo.jpg" /></A>
                    </TD>
                 </TR>
            </TABLE>
        </TD>
    </TR>
    </TABLE>    
    
    </BODY>
    </HTML>

  7. #7
    Mad Beach Bum jgsketch's Avatar
    Join Date
    Aug 2002
    Location
    FL
    Posts
    825
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm not sure how you got it to work. I deleted all of the inner code and left just the one script. It still did nothing for me. Since I can still pass session data, it must be the script itself still. Any other suggestions?

  8. #8
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,526
    Mentioned
    83 Post(s)
    Tagged
    3 Thread(s)
    Have a look at the getElementById parts of the script. If no elements exist with those id's, the script will fail. So you either need to ensure that those elements exist, or remove them from the script.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  9. #9
    Mad Beach Bum jgsketch's Avatar
    Join Date
    Aug 2002
    Location
    FL
    Posts
    825
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    So frustrating. I limited the script to just one element, the fname. I made sure that element had the same name across all of my pages and printed that value to the screen as well. Still did not redirect.

    Is the document.getElementById grabbing the session information or the form information? The reason I ask, I have a lead processing page in between the two pages. All this does is set the sessions from the form data and enters it into the database. It then redirects to the thank you page. If the document.getElementById is grabbing the form data, it will not see anything.

    If this is true, what do I use to insert the session data rather than the form data?

  10. #10
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,526
    Mentioned
    83 Post(s)
    Tagged
    3 Thread(s)
    Quote Originally Posted by jgsketch View Post
    If this is true, what do I use to insert the session data rather than the form data?
    you may have some trouble there for JavaScript cannot work with session data.

    About the most that can be done there is for server-side code to output session data and embed them within javascript code.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  11. #11
    Mad Beach Bum jgsketch's Avatar
    Join Date
    Aug 2002
    Location
    FL
    Posts
    825
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Can i encode the URL another way using just ASP? i have not seen any examples of this during my search. Or I could just combine the 2nd page and this thank you page. It would require extra programming though.Thanks for your help.

  12. #12
    Mad Beach Bum jgsketch's Avatar
    Join Date
    Aug 2002
    Location
    FL
    Posts
    825
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    So i'm trying to come up with ways around this. I can't believe I'm still trying to figure this out.

    I decided to pull in my session data and assign value to them. But I think I'm still doing it wrong by not assigning the values correctly. Because my script is still looking for the ElementId. I'm not sure how to make the javascript pickup on the new values that I assigned. Here is the session data code:

    HTML Code:
    <%
    fname = session("fname")
    lname = session("lname")
    email = session("email")
    state = session("state")
    %>

  13. #13
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,526
    Mentioned
    83 Post(s)
    Tagged
    3 Thread(s)
    Quote Originally Posted by jgsketch View Post
    HTML Code:
    <%
    fname = session("fname")
    lname = session("lname")
    email = session("email")
    state = session("state")
    %>
    Could you use ASP to output the values in to JavaScript variables?

    Code html4strict:
    <script type="text/javascript">
    var fname = '<% ... %>';
    var lname = '<% ... %>';
    ...
    </script>
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  14. #14
    Mad Beach Bum jgsketch's Avatar
    Join Date
    Aug 2002
    Location
    FL
    Posts
    825
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you for the help. That did it. I added the Var's and reformatted the redirect link and all is working. Happy Days


Bookmarks

Posting Permissions

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