If someone typed a swear word in a text box - the submit button would then be disabled (straight away) until they removed the word? - how would i do that?
If someone typed a swear word in a text box - the submit button would then be disabled (straight away) until they removed the word? - how would i do that?
Last edited by lankinator; 04-06-2007 at 06:16 AM.
It depends whether you want the submit button to be disabled as soon as the user types the word or when the user loses focus on the textbox.
as soon as the user types the word please.
attach an onkeydown handler to the textarea and keep checking if the contents of the textarea contains any of the bad words.
I think onkeyup would be a better choice but, it would be much more efficient, if the submit process is governed by a function, to simply abort the submit function if a bad word was found. Or, have a onmouseover event on the submit button to disable it if off color language was found.
- John________________________
Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate
jscheuer1: yep, the onkeyup handler would certainly be better.
lankinator: But implementation of a bad-word filter with javascript would be a very bad idea(with growing tools like firebug). An example case: if one has stored the bad-words in an array, any person with sufficient javascript knowledge could simply modify the array to be empty which would not lead to a very good filter.
Or just disable Javascript. It's acceptable as a user interface feature, but the definitive checking should be performed server-side.
Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!
I agree with Twey, I think server-side is the way to go.
How will disabling javascript disable the submit button? I agree that the final check to prevent swear words should be done server side. However, I am not aware of any server side method that will disable the submit button at either the moment that a user enters a 'bad' word or at the moment the user moves the mouse to submit.
I'm not saying that it cannot be done, I'm just fairly certain that it cannot be done. I'm always willing to learn new things.
- John________________________
Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate
jscheuer1: I think(but am not sure though), Twey meant that the javascript-swear-word-blocker won't work in cases where javascript is disabled, right Twey?
Bookmarks