- Feature Articles
- CodeSOD
- Error'd
- Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
Ignoring these design choices, and playing in the crappy little sandbox we're stuck in (knowing nothing of the surrounding..."architecture"), I would still rewrite it:
Admin
Obvious troll is obvious, but it's also wrong. default behavior on <input type="button" /> is submit.
Admin
Admin
Admin
Admin
Ergo, there is a place further up the stack that could appropriately workflow the disparate actions occurring in this validation routine.
tetsu's point stands.
Admin
But if you want to keep on appearing to be an idiot, by all means, stick to your silly preconceptions on validation. Just never read a book by a real GUI designer or you'll realize just how silly you've been all along…
Admin
I think my favorite part is actually this:
Admin
I've had this in New Zealand too - I emailed the site about the usability issues and they fixed it!
Now it deletes the character as soon as you type it - at least I had javascript enabled :)
Admin
My thought exactly. In fact, it could be made faster with char codes.
(of course add another condition for the characters in that range you still don't want)
Admin
OK. So originally it was an event handler for a number-only field. That's obvious, by the event handling code inside it. Also, since javascript does support calling a function without providing all the parameters, it still can.
First modification: It can also be called from another event handler so you can say "yo, handle decimal points too. Here are my parameters". This "handling" jumps it to a second input, presumably one that doesn't handle decimal points. Just like entering a license key in four textboxes that jump from one to the next.
Second modification: Control keys. So you can copy, paste, tab or submit. Might be useful, but that leaves it open to pasting ANYTHING. Though, this could be taken care of in on-submit validation.
Third modification: Takes capital letters. Hexadecimal? Just the alphabet for an alphanumeric code?
Fourth modification: OK, so now it takes all letters and can support full sentence structure (except apostrophe). WTF? Are you not using the numbers thing at all anymore? Because you just broke it.
Admin
Way to fail, bucko.
Admin
Admin
Admin
The reason for which it's called 'numbersonly' is that the guy took a ready-made function limiting input to numbers and expanded the character list not even bothering to correct the comments.
Admin
I thought about sending this piece of work from my college website's login form as a WTF but ended up not due to being too lazy to translate / annotate the code, but I guess I won't need to after all... :)
Interestingly, this breaks using 'tab' for switching fields on Firefox but not on IE6.
Admin
"any validation that occurs on every keypress is fundamentally wrong." I disagree. For instance, I recently filled in a secret message for the "verified by VISA" program. The message has to be 20-30 characters and has very strict restrictions on what characters may be included. For this case, I'd find it entirely reasonable to use the maxlength attribute so the browser would stop me from writing too long messages. Instead they opted to make a 10 lines long text entry field with a form submission that complained on mismatching length. And erased the entire message, if any invalid character was found. Way to make the user have to do computer work (counting letters) AND guess at what the requirements are.
Admin
Admin
Admin
Admin
TRWTF is that the function does not return FILE_NOT_FOUND under any circumstances.
Admin
It then got copied and extended.
Admin
ಠ_ಠ
Admin
And using HTML for anything at all is wrong because someone might use telnet instead of web-browser.
Admin
Actually javascript:while(1)alert("Thank you for enabling javascript") was the reason that i use Opera as my browser.
Admin
Actually, the first time I ever implemented a web browser, I used a telnet connection to grab the data from the server and pass it to my rendering engine. Telnet will deliver HTML just fine. In fact, a lot of the early web servers I connected to even responded to telnet option negotiation, leading me to believe the people writing homebrew servers were probably starting from a telnet server in the first place. :)
Admin
The RWTF is
// decimal point jump else if (dec && (keychar == ".")) { myfield.form.elements[dec].focus(); return false; }
when I enter a dot I am focussed to another field then the one I currently am.
Admin
Why this got posted in the first place is the biggest WTF ever.
The guy was obviously just trying to make his application more user friendly by adding a quick and simple input sanitation on the front-end. I can't believe you're nitpicking on a small snippet of JavaScript that actually works and fills its purpose.
Admin
Dude, seriously? If you actually need to validate something, that need does not vanish just because the client has no JavaScript. If you don't need to validate it, then why write a script in the first place?
Hopefully, the user input gui was provided by the JavaScript runtime itself, in which case this is not a WTF. But that isn't the case, is it?
Admin
EXACTLY!
Admin
It's just one letter.. Sheesh!
Admin
It seems I forgot the place in my browser(s) where i can disable JS.:)
Admin
why not use server side programming through a series of form submits to validate the form inputs? this is javascript agnostic and works quite well, esp if the page is lightweight (which form pages should be anyway).