View Full Version : form script

10-05-2002, 10:43 PM

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!


10-06-2002, 01:23 AM
What happened to 'document.domain'? :D


<input type="hidden" name="info">
<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';


10-06-2002, 03:34 AM

Thanks adios:thumbsup: . 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

10-06-2002, 03:58 AM
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'?

10-06-2002, 04:35 AM

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"?:confused: :mad:

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.


10-06-2002, 05:43 AM
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";

10-06-2002, 05:59 AM

Thanks Whammy!

10-06-2002, 06:00 AM

P.S. What products do I get? :D