|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
|
|
Ajax Application Generator Generate database and reporting .NET Web apps in minutes. Quickly create visually stunning, feature-rich apps that are easy to customize and ready to deploy. Download Now!
|
|
#1
|
|||
|
|||
|
Onblur help, please
Hi, All!
Can this be done? I am using this 'boilerplate' script attached 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? Thanks For Any Help! Joe |
|
#2
|
||||
|
||||
|
solution
this should do it...
Code:
<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] = "penis";
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";
//INSTEAD OF WHAT YOU DID, I JUST SEARCHED FOR THE "BADWORD", IF IT IS NOT THERE, IT WILL RETURN -1 WHICH IS CHECKED FOR, IF IT RETURNS MORE THEN -1, THERE IS AN INDEX OF THE WORD AND A BOOLEAN IS SET TO TRUE, LATER, IT IS CHECKED TO MAKE SURE THE BOOLEAN IS FALSE (NO PROFANITY).
profanityhere=false;
for (var j = 1; j <= numberOfWords; j++) {
if (isProfane[j].search(word[j])!=-1) {profanityhere=true;}
}
if (profanityhere) {
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>
the code you had before, i edited to go and search(), instead and if a word is there it will return an index for example... var str1="'the code you had before",str2="the code you badword had before"; if i were to go and have it search for that word... var ans1=str1.search("badword"); ans1 would = -1 because there is not index for the word "badword" var ans2=str2.search("badword"); ans2 would = 13 because the word "badword" starts at the index 13 hope this helps colton22 Last edited by colton22 : September 25th, 2006 at 04:25 PM. Reason: added description... |
![]() |
| Viewing: Dev Articles Community Forums > Programming > JavaScript Development > Onblur help, please |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|