I’ve got a small problem with the following code:
$('#body').keyup(function(){
var i = $('#body').val();
if(i.toLowerCase().indexOf("contact") >= 0){
$('#tosviolation').fadeIn('fast');
$('#sendForm').attr('action','send.php?f=1');
$('.toscontent').html("TOS Breach!");
} else {
$('#tosviolation').fadeOut('fast');
$('#sendForm').attr('action','send.php?f=0');
}
if(i.toLowerCase().indexOf("@") >= 0){
$('#tosviolation').fadeIn('fast');
$('#sendForm').attr('action','send.php?f=1');
} else {
$('#tosviolation').fadeOut('fast');
$('#sendForm').attr('action','send.php?f=0');
}
});
It checks whether #body (textarea) contains the values “contact” or/and “@”, and if this textarea does contain said values, it pops up / flashes a div telling the user that they’re violating the TOS. With the “@”, the box stays there when the user types it, yet when the user types “contact”, the box just flashes a few times and goes away, I’m guessing since “@” is 1 char long, and “contact” is 7 chars long, it’s something to do with that.
Then again, this is quite strange? I was intending it to just fadeIn() and stay faded in. I didn’t mind the flash, because of course, on keyup it’ll have to run the function every time the user taps a key, so that’s fine, but I can’t figure out how to keep it there when the user types “contact” somewhere in the textarea. Also, the other part where the it’s using the .attr() is directing the user to send.php, if it does contain “contact”,”@” — Then it pushes them to send.php?f=1, and if not, then send.php?f=0 — #sendForm is the ID of a form tag I have earlier, I assume this already works fine.
Does anyone know how to get the box to stay there once it’s pulled up with the data “contact” ?
Try this. Remember, setting the attribute of a form and relying on it for server-side processing is dangerous – the end user can easily fiddle with this before posting. You should validate again with the server and not use any GET variables sent with the form.