What’s up fellas? I’m trying to validate a form using a word filter script I found on the net and a blank message validator. I want to somehow combine the scripts. What’s happening now is if I post a blank message the alert will come up but the form will process anyway… same with the word filter. is there a way to fix this so it doesn’t process the form?
[code]
<SCRIPT LANGUAGE=”JavaScript”>
var swear_words_arr=new Array(“bloody”,”war”,”terror”);
var swear_alert_arr=new Array;
var swear_alert_count=0;
function reset_alert_count()
{
swear_alert_count=0;
}
function validate_message()
{
reset_alert_count();
var compare_text=document.replyform.message.value;
for(var i=0; i<swear_words_arr.length; i++)
{
for(var j=0; j<(compare_text.length); j++)
{
if(swear_words_arr[i]==compare_text.substring(j,(j+swear_words_arr[i].length)).toLowerCase())
{
swear_alert_arr[swear_alert_count]=compare_text.substring(j,(j+swear_words_arr[i].length));
swear_alert_count++;
}
}
}
var alert_text=””;
for(var k=1; k<=swear_alert_count; k++)
{
alert_text+=”n” + “(” + k + “) ” + swear_alert_arr[k-1];
}
if(swear_alert_count>0)
{
alert(“The form cannot be submitted.nThe following illegal words were found:n_______________________________n” + alert_text + “n_______________________________”);
document.replyform.message.select();
}
else
{
document.replyform.submit();
}
}
function select_area()
{
document.replyform.message.select();
}
window.onload=reset_alert_count;
return false;
</script>
<SCRIPT>
function validateForm (form) {
for (var e = 0; e < form.elements.length; e++) {
var el = form.elements[e];
if (el.type == ‘text’ || el.type == ‘textarea’ ||
el.type == ‘password’ || el.type == ‘file’ ) {
if (el.value == ”) {
alert(‘Please enter something in the text field, ‘ + el.name);
el.focus();
return false;
}
}
}
return true;
}
</SCRIPT>
<form ONSUBMIT=”return validateForm(this)” method=”POST” action=”replyprocess.asp?boardquer=<%=boardquer%>&game=<%=game%>&console=<%=console%>&topicid=<%=topicid%>&replyid=<%=replyid%>&boardid=<%=boardid%>” name=”replyform”>
<tr><td align=”center”><font class=”text3″><b>Title</b></font>
<p><input style=”background:#9A9A9A; border: 1 solid #000000; width: 500px; font-family: Verdana, Arial; font-size: 10px; color:#FFFFFF” type=”text” name=”Title” value=”<%=title%>” maxlength=”255″></p>
</td></tr>
<tr><td align=”center”><font class=”text3″><b>Message</b></font>
<p><textarea style=”background:#9A9A9A; border: 1 solid #000000; width: 500px; height: 100px; font-family: Verdana, Arial; font-size: 10px; color:#FFFFFF” area name=”message” onclick=”select_area()””>[quote]<%=rsreply(“description”)%>[/quote]</textarea>
</p>
<tr><td align=”center”><input type=”submit” value=”Submit” cursor:pointer” value=”Submit” onclick=”validate_message();”><input type=”reset” value=”Reset” name=”B2″></td></tr>
</form>