/    Sign up×
Community /Pin to ProfileBookmark

Help with a loop and domains

I’m trying to make a quick script that will stop certain domains from being entered into a form. I pieced together the script below but it doesn’t seem to work. I’m figuring it must be in the loop but I’m missing something. Any ideas?

[CODE]
function grabDomain(selectURL) {
var notURL = new Array()
notURL[0] = “tompegx.com”;
notURL[1] = “sysdvd.com”;
notURL[2] = “dvdtompegx.com”;
notURL[3] = “yaomingsoft.com”;
notURL[4] = “cutedvd.com”;
notURL[5] = “cnn-video.com”;
notURL[6] = “usa-download.com”;
notURL[7] = “tomp4.com”;
notURL[8] = “foxeasy.com”;

var the_url = document.addform.URL.value
var lead_slashes = the_url.indexOf(“//”);
var domain_start = lead_slashes + 2;
var without_resource = the_url.substring(domain_start, the_url.length);
var next_slash = without_resource.indexOf(“/”);
var domain = without_resource.substring(0, next_slash);

for (var i=0; i<selectURL; i++)
if (domain==notURL[i])
alert(“this domain is not allowed”);
}

<form name=”addform” action=”#” method=post>
<input name=”URL” value=”http://” size=”40″>
<input type=”submit” name=”add_record” onclick=”grabDomain();” value=”Submit”>
</form>[/CODE]

to post a comment
JavaScript

6 Comments(s)

Copy linkTweet thisAlerts:
@BigTony_NYCJul 31.2007 — I believe that for (i = 0; i&lt;selectURL; i++) should be for (i = 0; i&lt;notURL.length; i++)
Copy linkTweet thisAlerts:
@LeeUauthorJul 31.2007 — That didn't seem to do anything.
Copy linkTweet thisAlerts:
@vwphillipsJul 31.2007 — [CODE]<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<head>
<title></title>
</head>

<body>
<script language="JavaScript" type="text/javascript">
/*<![CDATA[*/
function grabDomain(selectURL) {
var notURL = new Array()
notURL[0] = "tompegx.com";
notURL[1] = "sysdvd.com";
notURL[2] = "dvdtompegx.com";
notURL[3] = "yaomingsoft.com";
notURL[4] = "cutedvd.com";
notURL[5] = "cnn-video.com";
notURL[6] = "usa-download.com";
notURL[7] = "tomp4.com";
notURL[8] = "foxeasy.com";
var domain=document.addform.URL.value;
for (var i=0; i<notURL.length; i++){
if (domain.match(notURL[i])){
alert("this domain is not allowed");
return false;
}
return true
}
return true
}
/*]]>*/
</script>


<form name="addform" onsubmit="return grabDomain();" action="#" method=post>
<input name="URL" value="http://" size="40">
<input type="submit" name="add_record" value="Submit">
</form>
</body>

</html>[/CODE]
Copy linkTweet thisAlerts:
@LeeUauthorJul 31.2007 — Vic,

It only works on the first one in the array, "tompegx.com".
Copy linkTweet thisAlerts:
@vwphillipsJul 31.2007 — woops, typo corrected

[CODE]<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<head>
<title></title>
</head>

<body>
<script language="JavaScript" type="text/javascript">
/*<![CDATA[*/
function grabDomain(selectURL) {
var notURL = new Array()
notURL[0] = "tompegx.com";
notURL[1] = "sysdvd.com";
notURL[2] = "dvdtompegx.com";
notURL[3] = "yaomingsoft.com";
notURL[4] = "cutedvd.com";
notURL[5] = "cnn-video.com";
notURL[6] = "usa-download.com";
notURL[7] = "tomp4.com";
notURL[8] = "foxeasy.com";
var domain=document.addform.URL.value;
for (var i=0; i<notURL.length; i++){
if (domain.match(notURL[i])){
alert("this domain is not allowed");
return false;
}
}
return true
}
/*]]>*/
</script>


<form name="addform" onsubmit="return grabDomain();" action="#" method=post>
<input name="URL" value="http://" size="40">
<input type="submit" name="add_record" value="Submit">
</form>
</body>

</html>[/CODE]
Copy linkTweet thisAlerts:
@LeeUauthorAug 01.2007 — Ahhh, that did it. Thanks!
×

Success!

Help @LeeU spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.5,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...