...

View Full Version : form script



cunning-fox
10-05-2002, 09:43 PM
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:)

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

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>

cunning-fox
10-06-2002, 02:34 AM
Hi,

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

adios
10-06-2002, 02: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'?
http://www.cs.uidaho.edu/x/icon_money.gif

cunning-fox
10-06-2002, 03:35 AM
:D

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.

Thanks

whammy
10-06-2002, 04: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";
}

cunning-fox
10-06-2002, 04:59 AM
VICTORY...

Thanks Whammy!

whammy
10-06-2002, 05:00 AM
:cool:

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



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum