Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



Reply
Old 09-23-2006, 08:58 AM Onblur help, please
Novice Talker

Posts: 12
Trades: 0
Hi, All!

Can this be done? I am using this 'boilerplate' script to validate a form. It currently gives a pop up if certain words are used (onblur). I would also like the script to redirect the user to another page if any of those words are used.

Am I being clear?

Here is the code I am using:

<textarea name="Comments" rows="5" cols="70" onBlur = "this.value = checkForProfanity(this.value);">


<SCRIPT LANGUAGE = "JavaScript">
<!--
var numberOfWords = 32;
var message = "Please read the submission guidelines again! We cannot accept your site at this time.";
var isProfane = new makeArray(numberOfWords);
var word = new makeArray(numberOfWords);

function checkForProfanity(usersInput) {

var temp = usersInput;
temp = temp.toLowerCase();

word[1] = "cialis";
word[2] = "viagra";
word[3] = "*****";
word[4] = "valium";
word[5] = "enlargement";
word[6] = "pharmacy";
word[7] = "hoodia";
word[8] = "phentermine";
word[9] = "badword9";
word[10] = "badword10";
word[11] = "badword11";
word[12] = "badword12";
word[13] = "badword13";
word[14] = "badword14";
word[15] = "badword15";
word[16] = "badword16";
word[17] = "badword17";
word[18] = "badword18";
word[19] = "badword19";
word[20] = "badword20";
word[21] = "badword21";
word[22] = "badword22";
word[23] = "badword23";
word[24] = "badword24";
word[25] = "badword25";
word[26] = "badword26";
word[27] = "badword27";
word[28] = "badword28";
word[29] = "badword29";
word[30] = "badword30";
word[31] = "badword31";
word[32] = "badword32";

for (var j = 1; j <= numberOfWords; j++) {
isProfane[j] = temp.indexOf(word[j]);
}


for (var j = 1; j <= numberOfWords; j++) {
if (isProfane[j] != -1) {
alert("We DO NOT accept this type of website \'"+word[j]+"\'.");
usersInput = message;
j = numberOfWords + 1; }

else {}
}
return usersInput;
}

function makeArray(n) {
this.length = n
for (var i = 1; i<=n; i++) {
this[i] = new String();
}
return this;
}
//-->
</SCRIPT>



Thanks For Any Help!
Joe
__________________

Please login or register to view this content. Registration is FREE
::
Please login or register to view this content. Registration is FREE
::
Please login or register to view this content. Registration is FREE
Captain Morgan is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 09-25-2006, 05:06 AM Re: Onblur help, please
Ultra Talker

Posts: 256
Location: Auckland, New Zealand
Trades: 0
Hey Joe,

To direct people to another location just do:

Code:
window.location.href = 'http://disney.go.com/';
Decided to go further and write the whole thing out:

HTML Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-NZ">
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
		<title>Bad Word Transfer</title>
		<script type="text/javascript">
			var profanities = new Array('badword1','badword2','badword3','badword4','badword5');
			function check_profanities(comments)
			{
				var is_profane = false;
				var alert_msg = 'We DO NOT accept that type of language:'+"\n";
				for (i in profanities)
				{
					if(comments.toLowerCase().match(profanities[i]))
					{
						is_profane = true;
						alert_msg += profanities[i]+"\n";
					}
				}
				if(is_profane)
				{
					alert_msg += 'I hope you enjoy Disney, goodbye.';
					alert(alert_msg);
					window.location.href = 'http://disney.go.com/';
					return false;
				}
				return true;
			}
		</script>
	</head>
	<body>
		<form action="" method="post" onsubmit="check_profanities(getElementById('comments').value);">
			<fieldset>
				<legend>Simple Form</legend>
				<ol>
					<li><label for="comments">Comments:</label> <textarea id="comments" name="comments" cols="25" rows="7" onblur="check_profanities(this.value);"></textarea></li>
				</ol>
				<div><input id="submit" name="submit" value="Send" alt="Send" type="submit" /></div>
			</fieldset>
		</form>
	</body>
</html>
Cheers,

MC
__________________
#------------------------------signature---------------------------------------------------------------------------------#
Quote:
I am well recognised for what I don't do than what I do. Chores are just one of those things.

Last edited by mastercomputers; 09-25-2006 at 05:38 AM..
mastercomputers is offline
Reply With Quote
View Public Profile Visit mastercomputers's homepage!
 
Old 09-25-2006, 06:01 PM Re: Onblur help, please
Novice Talker

Posts: 12
Trades: 0
WOW...THANKS for your time! It works exactly as I wanted

Thanks again,
Joe
__________________

Please login or register to view this content. Registration is FREE
::
Please login or register to view this content. Registration is FREE
::
Please login or register to view this content. Registration is FREE
Captain Morgan is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Onblur help, please
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.56150 seconds with 12 queries