• (cs)

    What kind of idiot knows Javascript, but doesn't know that you can (and should) put client-side event handlers into methods? Especially since he already is calling methods in the onclick code. Javascript ain't ASP.NET, buddy. There's no separation of code/presentation unless YOU make it happen.

    I'm guessing this is the result of a lazy programmer. "Eh, I wrote it and it works, so I never need to touch it again unless something is wrong."

  • Not Dorothy (unregistered) in reply to ObiWayneKenobi
    ObiWayneKenobi:
    What kind of idiot knows Javascript, but doesn't know that you can (and should) put client-side event handlers into methods?

    The situation is thus. You are a code monkey (JavaScript in this case), you are given a task - validate the input on this form. You sit in the dark being fed your tasks by you wise, all seeing project manager.

    The JavaScript monkey has not screwed up, his project manager has. Since when did the code monkeys have any input into a project?

  • Duckie (unregistered)

    Omg i didn't even know that you could have multiline code inside an event handler? Thank god for tagsoup parsers :D

  • (cs) in reply to Not Dorothy
    Not Dorothy:
    The JavaScript monkey has not screwed up, his project manager has. Since when did the code monkeys have any input into a project?

    How true that is :( Because, we all know the project manager, despite having never really written software, knows all about how it's written and how to manage those silly programmers who always talk about "refactoring" and "testing" instead of producing code that Sales can sell to clients so the CEO can earn his millions.

  • Rohan Prabhu (unregistered)

    how did the quotation mark(s) inside an attribute value ever work?

  • Vollhorst (unregistered)
    flag = validateRecord(form.res_Addr_1,form.res_City_1,form.res_County_1, form.res_State, form.res_Zip);
           
    if (flag == true)
    {       // validate start Date and End Date
      var dateflag = true;
      var day = "";
      dateflag = validate(form.res_MM, day,form.res_YYYY);
      if (dateflag == true)
      {
        dateflag = validate(form.res_MM_end, day, form.res_YYYY_end);
        if (dateflag == true)
        {
    All this silly indentation...
    if (validateRecord(form.res_Addr_1,form.res_City_1,form.res_County_1, form.res_State, form.res_Zip) && 
    validate(form.res_MM, "",form.res_YYYY) &&
    validate(form.res_MM_end, "", form.res_YYYY_end)){
    

    Why do so many programmers don't know bit operators?

  • Hans (unregistered)

    Can someone explain why this is a WTF for people who don't have a clue about web development?

  • Vollhorst (unregistered) in reply to Vollhorst
    Vollhorst:
    Why do so many programmers don't know bit operators?
    ... like myself. Damn... remove the bit bit. ;)
  • Phleabo (unregistered) in reply to Not Dorothy
    Not Dorothy:
    ObiWayneKenobi:
    What kind of idiot knows Javascript, but doesn't know that you can (and should) put client-side event handlers into methods?

    The situation is thus. You are a code monkey (JavaScript in this case), you are given a task - validate the input on this form. You sit in the dark being fed your tasks by you wise, all seeing project manager.

    The JavaScript monkey has not screwed up, his project manager has. Since when did the code monkeys have any input into a project?

    I have no idea what point you're trying to make. Are you trying to say that the project manager mandated that the coder not use functions or other basic hallmarks of good style?

  • Pyro (unregistered)

    I wonder if they check password with JavaScript on client side as well

  • Cosmin (unregistered)

    I can't agree with the fact that the PM screwed up. I would rather say that the recruiting/HR department did. This is stuff you just have to question and not take for granted even if you are just a coder. And if you really are a monkey, at least you could do is ask yourself "is it really normal to have such a long string as an attribute value? All other attribues seem to be a lot shorter. Hmmmmmmm".

  • Nulla (unregistered) in reply to Vollhorst

    Perhaps it's the same reason that some don't know the difference between a bit operator and a logical operator.

  • (cs) in reply to Hans
    Hans:
    Can someone explain why this is a WTF for people who don't have a clue about web development?

    There's a 66 line javascript function inside an HTML attribute. Attributes are never supposed to be more than a few words. The correct way to handle this would be to put the javascript somewhere else (like, in an actual function declaration) and call it from the handler, or even better, put an onload function somewhere that attaches the onclick handler at start so there isn't any javascript in the HTML at all.

  • Vempele (unregistered) in reply to Nulla
    Nulla:
    Perhaps it's the same reason that some don't know the difference between a bit operator and a logical operator.

    if (validateRecord(form.res_Addr_1,form.res_City_1,form.res_County_1, form.res_State, form.res_Zip) & validate(form.res_MM, "",form.res_YYYY) & validate(form.res_MM_end, "", form.res_YYYY_end))) {

    will work just fine assuming those functions don't have side effects. :p

  • me (unregistered) in reply to Nulla
    Nulla:
    Perhaps it's the same reason that some don't know the difference between a bit operator and a logical operator.
    Aha! So that's what he was talking about. I read that post like three times trying to figure out where bit operators had anything to do with it...
  • Stupidumb (unregistered) in reply to Vollhorst
    Vollhorst:
    All this silly indentation...
    if (validateRecord(form.res_Addr_1,form.res_City_1,form.res_County_1, form.res_State, form.res_Zip) && 
    validate(form.res_MM, "",form.res_YYYY) &&
    validate(form.res_MM_end, "", form.res_YYYY_end)){
    

    Why do so many programmers don't know bit operators?

    Those aren't bit operators.

  • (cs) in reply to Vollhorst
    Vollhorst:
    Why do so many programmers don't know bit operators?
    Because they're two-bit operators?
  • (cs)

    What?

    <click> Ouch!

  • Pez (unregistered) in reply to gxti
    gxti:
    Hans:
    Can someone explain why this is a WTF for people who don't have a clue about web development?

    There's a 66 line javascript function inside an HTML attribute. Attributes are never supposed to be more than a few words. The correct way to handle this would be to put the javascript somewhere else (like, in an actual function declaration) and call it from the handler, or even better, put an onload function somewhere that attaches the onclick handler at start so there isn't any javascript in the HTML at all.

    There should also be a server side failback so users who have Javascript turned off still get the same functionality. Helps usability and security no end. Personally, I wouldn't bother with Javascript validation and just do it on the server

  • Sampson (unregistered)

    Unless you are coding in LISP, where you may end up with 7,8,9 levels of nested brackets to close, adding this kind of crap to code is just annoying.

    } // end if

    especially when the opening if statement is THREE lines above!

  • Tj (unregistered)

    I dont know to me it looks like this is Five-fingered code that someone who didnt know better, like a marketer or graphic designer slapped into the page. The annoying comments are somethings that you keep your place as a new programmer, 2-3 weeks maybe, or when you get paid by the line.

  • (cs)

    Hmmm, why does the post have a vertical scrollbar (especially since only one line is hidden)? And, more importantly, why does it have a horizontal one? (1024x768)

  • (cs) in reply to ObiWayneKenobi
    ObiWayneKenobi:
    What kind of idiot knows Javascript, but doesn't know that you can (and should) put client-side event handlers into methods? Especially since he already is calling methods in the onclick code. Javascript ain't ASP.NET, buddy. There's no separation of code/presentation unless YOU make it happen.

    I'm guessing this is the result of a lazy programmer. "Eh, I wrote it and it works, so I never need to touch it again unless something is wrong."

    I bet his name is Habib Abdul Habaldoasdkdsdkfdsusmuck.

  • (cs)

    It's a little known fact that Dante's Inferno is actually a metaphorical description of JavaScript:

    "Dark, profound it was, and cloudy, so that though I fixed my sight on the bottom I did not discern anything there."

  • (cs) in reply to ObiWayneKenobi
    ObiWayneKenobi:
    What kind of idiot knows Javascript, but doesn't know that you can (and should) put client-side event handlers into methods?
    I believe you mean "functions", not "methods".
  • (cs) in reply to Hans
    Hans:
    Can someone explain why this is a WTF for people who don't have a clue about web development?
    It's a two parter. First, the coder is doing all of the validation on the client side (web browser). Which violates one of the first rules of web programming: Don't Trust What the Client Sends. It is trivial to turn off javascript thereby skipping all of the client side validation. All of this code should have been processed on the server as well.

    Second, readability is a nightmare. So, instead of putting all of the javascript code inside of an HTML attribute, it should have been stored in either its own javascript file or in the page header. This would leave a simple, very readable, function call as the button's onclick handler.

  • JK (unregistered) in reply to Vollhorst

    ================= if (validateRecord(form.res_Addr_1,form.res_City_1,form.res_County_1, form.res_State, form.res_Zip) && validate(form.res_MM, "",form.res_YYYY) && validate(form.res_MM_end, "", form.res_YYYY_end)){

    Why do so many programmers don't know bit operators?

    Ummm... those are LOGICAL operators, buddy, not bitwise operators. Quite a difference.

  • (cs) in reply to clively
    clively:
    Hans:
    Can someone explain why this is a WTF for people who don't have a clue about web development?
    It's a two parter. First, the coder is doing all of the validation on the client side (web browser). Which violates one of the first rules of web programming: Don't Trust What the Client Sends. It is trivial to turn off javascript thereby skipping all of the client side validation. All of this code should have been processed on the server as well.

    Second, readability is a nightmare. So, instead of putting all of the javascript code inside of an HTML attribute, it should have been stored in either its own javascript file or in the page header. This would leave a simple, very readable, function call as the button's onclick handler.

    I'm not wholly convinced. Sure, the lack of server-side validation is dumb, but that happens too often to merit a WTF.

    I don't really see how "readability" is a nightmare, either. Firstly, it's Javascript. Javascript is not readable, IMO. Secondly, it would be equally unreadable if wrapped in a function call.

    What I think we have here is a Perl programmer trying to carry the concept of anonymous subroutines across to Javascript. Not the world's brightest idea, granted, but more of a giggle than a WTF.

  • vigge (unregistered) in reply to Vollhorst
    Vollhorst:
    if (validateRecord(form.res_Addr_1,form.res_City_1,form.res_County_1, form.res_State, form.res_Zip) && 
    validate(form.res_MM, "",form.res_YYYY) &&
    validate(form.res_MM_end, "", form.res_YYYY_end)){
    
    Why do so many programmers don't know bit operators?

    Although those aren't bit operators in your example, are they (afaik they're called logical operators)?

  • KM (unregistered) in reply to real_aardvark

    There are anonymous functions in Javascript.

  • Anita Job (unregistered) in reply to Pez
    Pez:
    Personally, I wouldn't bother with Javascript validation and just do it on the server

    Validating user input on the client side in addition to the server can improve server performance by reducing the number of calls to the server that contain invalid data, and the subsequent calls needed to resubmit the corrected data.

    CAPTCHA: 'duis' - Don't drink and drive and you won't get any! [~])

  • G (unregistered)

    At least its commented!

    // end comment

  • (cs) in reply to Phleabo
    Phleabo:
    Not Dorothy:
    ObiWayneKenobi:
    What kind of idiot knows Javascript, but doesn't know that you can (and should) put client-side event handlers into methods?

    The situation is thus. You are a code monkey (JavaScript in this case), you are given a task - validate the input on this form. You sit in the dark being fed your tasks by you wise, all seeing project manager.

    The JavaScript monkey has not screwed up, his project manager has. Since when did the code monkeys have any input into a project?

    I have no idea what point you're trying to make. Are you trying to say that the project manager mandated that the coder not use functions or other basic hallmarks of good style?

    I think he's saying that the coder just wrote the code, and then the manager told the HTML guy to put that code into the onClick; the JS coder didn't know that the code he wrote would be shoved into an HTML attribute

  • John Doe (unregistered) in reply to Phleabo

    Ouch, did we hit a new low when merely the use of functions is considered a "basic hallmark of good style"?

    At least the guy was using functions for the validations...

  • rbonvall (unregistered) in reply to Hans
    Hans:
    Can someone explain why this is a WTF for people who don't have a clue about web development?
    There is no wooden table.
  • (cs) in reply to Lysis
    Lysis:
    ObiWayneKenobi:
    What kind of idiot knows Javascript, but doesn't know that you can (and should) put client-side event handlers into methods? Especially since he already is calling methods in the onclick code. Javascript ain't ASP.NET, buddy. There's no separation of code/presentation unless YOU make it happen.

    I'm guessing this is the result of a lazy programmer. "Eh, I wrote it and it works, so I never need to touch it again unless something is wrong."

    I bet his name is Habib Abdul Habaldoasdkdsdkfdsusmuck.

    I bet you're a retarded redneck racist moron, but unlike you, I have at least some evidence for my theory: your own words.

  • tekiegreg (unregistered)

    My theory was that some sort of GUI generator tool did that, I've never, never seen anything vaguely resembling that before and it looks like someone just typed a whole script into an OnClick() prompt in a prompt somewhere

  • (cs) in reply to John Doe
    John Doe:
    Ouch, did we hit a new low when merely the use of functions is considered a "basic hallmark of good style"?

    We hit that low a long time ago, Winston.

  • doggerel (unregistered)

    Wouldn't that have broken by the first " character?

  • (cs)

    I guess he used something like <input onclick="<?php include 'script.js' ?>" ...>

  • Barf 4 eva (unregistered) in reply to Zylon
    Zylon:
    ObiWayneKenobi:
    What kind of idiot knows Javascript, but doesn't know that you can (and should) put client-side event handlers into methods?
    I believe you mean "functions", not "methods".

    heh, methods or functions? :P Sounds like a meaningless and improper OR statement to me, but then again... Perhaps this is a point clarified specifically within javascript? I don't do JavaScript... buuuuut..

    I always believed a method to be a generalization of EITHER a procedure OR a function, where method is more inclusive, in which case, a function is a method.

  • Ahnfelt (unregistered) in reply to ObiWayneKenobi
    ObiWayneKenobi:
    What kind of idiot knows Javascript, but doesn't know that you can (and should) put client-side event handlers into methods? Especially since he already is calling methods in the onclick code. Javascript ain't ASP.NET, buddy. There's no separation of code/presentation unless YOU make it happen.

    I'm guessing this is the result of a lazy programmer. "Eh, I wrote it and it works, so I never need to touch it again unless something is wrong."

    A truly lazy programmer knows that this will cause trouble later on, and tries to get it first the right time so he doesn't have to touch it again. Don't mistake incompetence as laziness. Laziness is a virtue in programming and any other field where you have to maintain what you've built.

  • (cs) in reply to Barf 4 eva
    Barf 4 eva:
    heh, methods or functions? :P Sounds like a meaningless and improper OR statement to me, but then again... Perhaps this is a point clarified specifically within javascript? I don't do JavaScript... buuuuut..
    Function verb(object);

    Method object.verb();

    An oversimplification to be sure, but it gets to the heart of the distinction. And Javascript does support both approaches.

  • Habib Abdul Habaldoasdkdsdkfdsusmuck (unregistered) in reply to Lysis
    Lysis:
    I bet his name is Habib Abdul Habaldoasdkdsdkfdsusmuck.

    Casual racism never goes out of style, does it?

  • Barf 4 eva (unregistered) in reply to Zylon
    Zylon:
    Barf 4 eva:
    heh, methods or functions? :P Sounds like a meaningless and improper OR statement to me, but then again... Perhaps this is a point clarified specifically within javascript? I don't do JavaScript... buuuuut..
    Function verb(object);

    Method object.verb();

    An oversimplification to be sure, but it gets to the heart of the distinction. And Javascript does support both approaches.

    heh, thanks for the explanation, do appreciate it!

    I THINK what is meant, and I'm probably off (have a tendency to be..) is that a method exists via instantiation of an object whereas the function is a static implementation? (IE: I use a static class such as the Math lib to use the static math FUNCTIONS) I never hear much about the difference between methods and functions in C#, but I figured this is what you were getting at maybe? :P Sorry, from a Delphi perspective (don't ask!) you have procedures which don't return anything vs functions, which have a return type -- I used this as the basis of all existing as methods.

    Again, thanks for clarifying!

  • Jon (unregistered)

    oh man, that's awesome that scrolling wrapper around the article that means the stupid thing is unreadable because every line extends off to the right of the div... clap

  • Code Monkey Like Fritos (unregistered) in reply to Phleabo
    Phleabo:
    Not Dorothy:
    ObiWayneKenobi:
    What kind of idiot knows Javascript, but doesn't know that you can (and should) put client-side event handlers into methods?

    The situation is thus. You are a code monkey (JavaScript in this case), you are given a task - validate the input on this form. You sit in the dark being fed your tasks by you wise, all seeing project manager.

    The JavaScript monkey has not screwed up, his project manager has. Since when did the code monkeys have any input into a project?

    I have no idea what point you're trying to make. Are you trying to say that the project manager mandated that the coder not use functions or other basic hallmarks of good style?

    Code monkey very diligent, but his output stink. His code not functional or elegant, what do code monkey think?

    Code monkey think maybe manager wanna write god damn login page himself!

    Code monkey not say it, out loud code monkey not crazy, just proud.

  • mabinogi (unregistered) in reply to Zylon
    Zylon:
    Barf 4 eva:
    heh, methods or functions? :P Sounds like a meaningless and improper OR statement to me, but then again... Perhaps this is a point clarified specifically within javascript? I don't do JavaScript... buuuuut..
    Function verb(object);

    Method object.verb();

    An oversimplification to be sure, but it gets to the heart of the distinction. And Javascript does support both approaches.

    That's a pretty meaningless distinction.

    In that example, method is the name people give to member functions of a class when they want to sound like they know Object Oriented programing, but don't know it well enough to call them messages.

    A method or message is a function that is designed to operate on or expose the internal state of an object.

    It's entirely possible to have verb(object) functions that are actually methods - particularly in non natively object oriented languages, and it's also equally possible (but not necessarily good design) to have object.verb() functions that are just functions, and do nothing with the state of the object they're bound to.

  • (cs)

    Oooh.. this looks like something Brice Richard would do if he knew javascript!

    And speaking of truncation, anyone else notice that the wtf text has a scrollbar? But it's long enough so that you can't see the bottom scrollbar. It's effectively truncated unless you're running a full screen browser at ~1600x1200 or better (at least in IE7)!

  • (cs) in reply to tekiegreg
    tekiegreg:
    My theory was that some sort of GUI generator tool did that, I've never, never seen anything vaguely resembling that before and it looks like someone just typed a whole script into an OnClick() prompt in a prompt somewhere
    That's another good theory. I still like my Perl theory, though (if only because CGI makes it reasonably plausible):
    KM:
    There _are_ anonymous functions in Javascript.
    And presumably committed Javascript programmers are unable to discriminate between the "Reply" button and the "Quote" button. Never mind, at least I know what you mean.

    Yes, thank you, I know there are anonymous functions in Javascript. But why bother with all that "function(blah) { // Further blah, possibly involving the DOM } when you can just encase the whole lot in double quotes? Genius, I tell you, genius.

    And admittedly the OP doesn't look like Perl's anonymous subroutines (leaving aside the stuff to do with closures). Yup, Perl is almost equally verbose: sub # No blah here!\n { # blah\n }.

    However, the great thing about this particular idiom is that it effectively combines Perl's anonymous subroutines with Perl's "here-doc" technique to provide what any Java programmer worth their salt would recognise as a Singleton Pattern.

    Brillant! Brillant!! Brillant!!!

    Of course, it's still bloody stupid.

    BTW, Is it just me, or does ECMAScript sound like a peculiarly horrible combination of tattoos and a rather unpleasant skin disease?

Leave a comment on “OnClick Does What?!”

Log In or post as a guest

Replying to comment #172268:

« Return to Article