Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8

Thread: form script

  1. #1
    New Coder
    Join Date
    Jun 2002
    Posts
    58
    Thanks
    0
    Thanked 0 Times in 0 Posts

    form script

    Hi,

    I need to capture the "location.hostname" into a field named "info" in a form.

    Then I need a second script that checks the field "info", and if that field does not contain the word "endlesscashflow.com", then the page is forwarded to "www.somewhere.com".

    This would greatly be appreciated!



    Thanks

  • #2
    Senior Coder
    Join Date
    Jun 2002
    Posts
    1,404
    Thanks
    2
    Thanked 32 Times in 32 Posts
    What happened to 'document.domain'?

    OK.

    <html>
    <head>
    <title>untitled</title>
    </head>
    <body>
    <form>
    <input type="hidden" name="info">
    </form>
    <script type="text/javascript" language="javascript">

    var hn = location.hostname;
    document.forms[0].info.value = hn;
    if (hn.indexOf('endlesscashflow.com') == -1) self.location = 'http://www.somewhere.com';

    </script>
    </body>
    </html>
    Last edited by adios; 10-06-2002 at 04:00 AM.

  • #3
    New Coder
    Join Date
    Jun 2002
    Posts
    58
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi,

    Thanks adios . There were some errors that I couldn't avoid though. I successfully managed to get the "location.hostname" to put "www.endlesscashflow.com" into the field.

    There is one more thing I need now (hopefully the last). How would you translate this into javascript:

    If the field "info" does not contain the word "endlesscashflow.com", then send them to www.nowhere.com, in very simple code.




    Thanks again

  • #4
    Senior Coder
    Join Date
    Jun 2002
    Posts
    1,404
    Thanks
    2
    Thanked 32 Times in 32 Posts
    var val = document.form_name.info.value;
    if (val.indexOf('endlesscashflow.com') == -1) self.location = 'http://www.nowhere.com';

    Where can I find out more about 'endlesscashflow'?

  • #5
    New Coder
    Join Date
    Jun 2002
    Posts
    58
    Thanks
    0
    Thanked 0 Times in 0 Posts


    I'll be sure to let you know, very soon, I hope.

    You know what I just realized? Even when I visit the page that shows "hostname.location" in a field from visiting yahoo.com, it still shows endlesscashflow.com in that field??? Shouldn't it be "yahoo.com"?

    I am confused. All I want to do here is make sure that anyone who visits this page is coming from a page already on my domain. And if they are not, I want them redirected.

    Maybe some type of "referrer" line is needed that can discriminate based upon the root of the domain (something.com instead of a specific page)?

    I would be glad to give someone one of our products if they can do this.

    Thanks
    Last edited by cunning-fox; 10-06-2002 at 05:43 AM.

  • #6
    Senior Coder
    Join Date
    Jun 2002
    Location
    41° 8' 52" N -95° 53' 31" W
    Posts
    3,660
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Do a search for document.referrer - it can be used in the same way shown above (regarding indexOf) - and I think that's what you're looking for in the first place.

    P.S. Note that document.referrer will be empty if someone navigates straight to the page or has javascript disabled - but in your case, I don't think that will matter... and that will also eliminate your need to use a hidden field...

    if (document.referrer.indexOf("endlesscashflow.com") == -1){
    window.location = "http://www.barbie.com";
    }
    Last edited by whammy; 10-06-2002 at 06:03 AM.
    Former ASP Forum Moderator - I'm back!

    If you can teach yourself how to learn, you can learn anything. ;)

  • #7
    New Coder
    Join Date
    Jun 2002
    Posts
    58
    Thanks
    0
    Thanked 0 Times in 0 Posts
    VICTORY...

    Thanks Whammy!

  • #8
    Senior Coder
    Join Date
    Jun 2002
    Location
    41° 8' 52" N -95° 53' 31" W
    Posts
    3,660
    Thanks
    0
    Thanked 0 Times in 0 Posts


    P.S. What products do I get?
    Former ASP Forum Moderator - I'm back!

    If you can teach yourself how to learn, you can learn anything. ;)


  •  

    Posting Permissions

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