• kipthegreat (cs)

    A selecter, huh?  So what's the selectest!

  • AndrewVos (unregistered)

    Dare I say "Javascript has the best WTF's" ?

  • rmr (cs)

    Rofl, so if I'm reading this right, if he has 10, 210, 310 and 410 checked, and he unchecks 10, he ends up with 234 checked?  Good thing the ids are so high!

    What does the g in the eval line do?

  • kipthegreat (cs) in reply to rmr
    rmr:
    Rofl, so if I'm reading this right, if he has 10, 210, 310 and 410 checked, and he unchecks 10, he ends up with 234 checked?  Good thing the ids are so high!

    What does the g in the eval line do?


    g = global replace.  otherwise, only the first "10," would be replaced.
  • sammybaby (cs)
    Alex Papadimoulis:

    The root folder housed over 400 of files, most belonging to completely different modules. Actually, there was one subfolder: it contained all the code and pages for the previous programmer's World of Warcraft clan website.



    I was originally going to make a joke about the javascript as an effort to make sure that the checked checkboxes were, like, really checked, so they didn't have a situation like the 2000 Florida vote with the hanging chads and whatnot.

    Then I re-read the bit about the WoW site and though, aw, hell, that's funnier than anything I could come up with anyway.
  • kipthegreat (cs)

    I guess he is unfamiliar with $_POST in PHP?

  • trippyz (cs)

    Is it safe to remove my welding goggles yet?

  • CodeRage (cs) in reply to kipthegreat
    kipthegreat:
    rmr:
    Rofl, so if I'm reading this right, if he has 10, 210, 310 and 410 checked, and he unchecks 10, he ends up with 234 checked?  Good thing the ids are so high!
    What does the g in the eval line do?

    g = global replace.  otherwise, only the first "10," would be replaced.

    Yeah, this is awesome!  For fun, paste this code on your machine at work, add some checkboxes where the ids are substrings of the other ids, and change the hidden input to text so you can see it as it messes up the list of ids.

    And all this for something the browser does for you when it posts the form, had the developer been 1337 enough to give all the checkboxes the same name, with each value being the id.
  • Digitalbath (cs) in reply to CodeRage

    CodeRage:
    kipthegreat:
    rmr:
    Rofl, so if I'm reading this right, if he has 10, 210, 310 and 410 checked, and he unchecks 10, he ends up with 234 checked?  Good thing the ids are so high!
    What does the g in the eval line do?

    g = global replace.  otherwise, only the first "10," would be replaced.

    Yeah, this is awesome!  For fun, paste this code on your machine at work, add some checkboxes where the ids are substrings of the other ids, and change the hidden input to text so you can see it as it messes up the list of ids.

    And all this for something the browser does for you when it posts the form, had the developer been 1337 enough to give all the checkboxes the same name, with each value being the id.

    Yes, but then he wouldn't be able to handle "input" from mutliple pages in his insert.php file.  At least that's what i'm guessing he did.  Based on the prefix of fthe checkboxes, he probably had some huge switch statement in that file that knew what values were selected on what page.  It's the new duct tape...insert.php!

    Or, am I completely off here?

  • Digitalbath (cs)

    I did not interpret "in trouble" as getting fired.  If he did not get fired for trying to sell proprietary software on eBay...that might be a bigger WTF than his whole system.

  • merreborn (cs) in reply to kipthegreat
    kipthegreat:
    I guess he is unfamiliar with $_POST in PHP?


    Unnecessary:  assuming the point of this was to convert a POST to a GET, all he had to do was change
    <form method="POST"> to <form method="GET">


    I'm pretty sure GET is the default anyway.  I can't for the life of me figure out why the fuck he thought he needed the javascript.
  • rocksanddirt (unregistered) in reply to AndrewVos

    As javascript in itself was designed with good intentions, there are many facets about the language and the varying browser capabilities that can eventually drive your code into WTFland for the next developer...

  • Gnictigezoink (unregistered)

    Holy crap.

    Err. Unholy Crap.

    'Nother instance of "TTWTASO" design pattern (trash the whole thing and start over)

  • wyz (unregistered)

    The story around it is differenct, or this could be jscript from the place I at now as an on-site contractor!

    This job was presumably modifying about 8 web pages. But it turned out the pages had server-side jscript rendering client-side jscript with this kind of garbage code, plus putting values in and out of XML strings by someone not knowing how to use XML. That just my rant on the web pages! 

    In fact, some samples were submitted to WTF, but Alex only had sympathy for me. Don't recall if it was duplicate stuff or wasn't humorous enough to use. But it has kept some of my sanity reading WTF and seeing I'm not the only one dealing with bad coding and applications.

    (Someone had to ask real nice to get me to come here and rescue a project that was sinking. The first guy placed here couldn't figure out what to do.)

     

  • Aximilation (cs)

    Oh yes, forget the whole $_REQUEST.....very nice. I've always wanted to create the new and improved version of that. Lol...
    It's almost as bad as the new link tag seen elsewhere on this site last week...
    <a onclick="location='http://www.aximilation.com'; return false;" href="#">The <em>new</em> link!</a>
    (I'm making a t-shirt!)

  • obediah (cs) in reply to Digitalbath
    Digitalbath:

    Yes, but then he wouldn't be able to handle "input" from mutliple pages in his insert.php file.  At least that's what i'm guessing he did.  Based on the prefix of fthe checkboxes, he probably had some huge switch statement in that file that knew what values were selected on what page.  It's the new duct tape...insert.php!

    Or, am I completely off here?



    This is what happens when someone hears the term 'MVC' in passing and then reads a random blog post. Because nothing controls like a single file with 20,000 if statements.
  • Anon (unregistered)
    Alex Papadimoulis:

    <span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">script</span><span style="COLOR: #ff0000"> type<span style="COLOR: #0000ff">="text/javascript"</span></span><span style="COLOR: #0000ff">&gt;</span> <span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">!--</span><span style="COLOR: #000000"><br><br>function onCheck(id)<br>{<br>&nbsp; checkedValues = document.selecter.checkedValues;<br>&nbsp; checkedBox = document.selecter["check_"+id];<br>&nbsp; <br>&nbsp; if (!checkedBox.checked)<br>&nbsp;&nbsp;&nbsp; checkedValues.value = <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; eval("checkedValues.value.replace(/" +id + ',' + "/g,'')");<br>&nbsp; else<br>&nbsp;&nbsp;&nbsp; <font size="4"><strong>checkedValues.value+=(id+',');</strong><br></font>}<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br>function submit()<br>{<br>&nbsp; document.location.href = 'insert.php?chosen=' + <br>&nbsp;&nbsp;&nbsp;&nbsp; document.selecter.checkedValues.value;<br>&nbsp; return false;<br>}<br><br><br>//--</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">script</span><span style="COLOR: #0000ff">&gt;</span>

    <span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">form</span><span style="COLOR: #ff0000"> id<span style="COLOR: #0000ff">="selecter"</span> name<span style="COLOR: #0000ff">="selecter"</span></span><span style="COLOR: #0000ff">&gt;</span>
      <span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">input</span><span style="COLOR: #ff0000"> type<span style="COLOR: #0000ff">="hidden"</span> id<span style="COLOR: #0000ff">="checkedValues"</span> name<span style="COLOR: #0000ff">="checkedValues"</span> </span><span style="COLOR: #0000ff">/&gt;</span>
      <span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">input</span><span style="COLOR: #ff0000"> class<span style="COLOR: #0000ff">="button"</span> type<span style="COLOR: #0000ff">="button"</span> value<span style="COLOR: #0000ff">="Submit"</span> onclick<span style="COLOR: #0000ff">="submit()"</span> </span><span style="COLOR: #0000ff">/&gt;</span>

      <span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">input</span><span style="COLOR: #ff0000"> id<span style="COLOR: #0000ff">="check_4273844"</span> onclick<span style="COLOR: #0000ff">="onCheck('4273844')"</span> type<span style="COLOR: #0000ff">="checkbox"</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; name<span style="COLOR: #0000ff">="check_4273844"</span> <strong><font size="4">value<span style="COLOR: #0000ff">="ON"</span></font></strong> </span><span style="COLOR: #0000ff">/&gt;</span>
      ...
      <span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">input</span><span style="COLOR: #ff0000"> id<span style="COLOR: #0000ff">="check_4273843"</span> onclick<span style="COLOR: #0000ff">="onCheck('4273843')"</span> type<span style="COLOR: #0000ff">="checkbox"</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; name<span style="COLOR: #0000ff">="check_4273843"</span> <strong><font size="4">value<span style="COLOR: #0000ff">="ON"</span></font></strong> </span><span style="COLOR: #0000ff">/&gt;</span>
      ...
      <span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">input</span><span style="COLOR: #ff0000"> id<span style="COLOR: #0000ff">="check_4273842"</span> onclick<span style="COLOR: #0000ff">="onCheck('4273842')"</span> type<span style="COLOR: #0000ff">="checkbox"</span> <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; name<span style="COLOR: #0000ff">="check_4273842"</span> <strong><font size="4">value<span style="COLOR: #0000ff">="ON"</span></font></strong> </span><span style="COLOR: #0000ff">/&gt;</span>
      ...
    <span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">form</span><span style="COLOR: #0000ff">&gt;</span>

    Notice the bolded parts.  When the page loads, all the boxes are checked.  If you submit without un-checking and re-checking the box you want, there is no value in the "checkedValues" field.

  • biziclop (cs) in reply to Aximilation
    Aximilation:
    Oh yes, forget the whole $_REQUEST.....very nice. I've always wanted to create the new and improved version of that. Lol...
    It's almost as bad as the new link tag seen elsewhere on this site last week...
    <a onclick="location='http://www.aximilation.com'; return false;" href="#">The <em>new</em> link!</a>
    (I'm making a t-shirt!)


    Resistance is futile.
  • foo (unregistered)

    It's so beautiful! I'm crying... no wait... that's blood... FROM MY EYES!

  • maht (unregistered)

    the guy almost invented Ajax

  • Anon (unregistered) in reply to Anon
    Anonymous:

    Notice the bolded parts.  When the page loads, all the boxes are checked.  If you submit without un-checking and re-checking the box you want, there is no value in the "checkedValues" field.

    Wait, I was wrong.  That doesn't say "checked" it says "on".  This was so stupid I mentally filled in what he should have been doing instead of what he actually did.

     

    Wow, that's a lot of work to be so wrong.

  • Tomer Chachamu (unregistered) in reply to Anon

    Actually, 'value="ON"' does not mean the box is checked. It just means that if it is checked, the value to send to the server is "ON".

    Considering that that value presumbly isn't used (since checkedValues.value holds the list of checked checkboxes) you have to wonder why it's there. Just another copy-paste job, I suppose...

  • snoofle (cs) in reply to Anon
    Anonymous:
    Anonymous:

    Notice the bolded parts.  When the page loads, all the boxes are checked.  If you submit without un-checking and re-checking the box you want, there is no value in the "checkedValues" field.

    Wait, I was wrong.  That doesn't say "checked" it says "on".  This was so stupid I mentally filled in what he should have been doing instead of what he actually did.

    Wow, that's a lot of work to be so wrong.

    Web-neophyte here - I thought check boxes could only be true/false, or possibly [un]checked. "On" ???

  • ole gustie (unregistered) in reply to Anon
    Anonymous:
    Alex Papadimoulis:

    <span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">script</span><span style="COLOR: #ff0000"> type<span style="COLOR: #0000ff">="text/javascript"</span></span><span style="COLOR: #0000ff">&gt;</span> <span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">!--</span><span style="COLOR: #000000"><br><br>function onCheck(id)<br>{<br>&nbsp; checkedValues = document.selecter.checkedValues;<br>&nbsp; checkedBox = document.selecter["check_"+id];<br>&nbsp; <br>&nbsp; if (!checkedBox.checked)<br>&nbsp;&nbsp;&nbsp; checkedValues.value = <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; eval("checkedValues.value.replace(/" +id + ',' + "/g,'')");<br>&nbsp; else<br>&nbsp;&nbsp;&nbsp; <font size="4"><strong>checkedValues.value+=(id+',');</strong><br></font>}<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br>function submit()<br>{<br>&nbsp; document.location.href = 'insert.php?chosen=' + <br>&nbsp;&nbsp;&nbsp;&nbsp; document.selecter.checkedValues.value;<br>&nbsp; return false;<br>}<br><br><br>//--</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">script</span><span style="COLOR: #0000ff">&gt;</span>

    <span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">form</span><span style="COLOR: #ff0000"> id<span style="COLOR: #0000ff">="selecter"</span> name<span style="COLOR: #0000ff">="selecter"</span></span><span style="COLOR: #0000ff">&gt;</span>
      <span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">input</span><span style="COLOR: #ff0000"> type<span style="COLOR: #0000ff">="hidden"</span> id<span style="COLOR: #0000ff">="checkedValues"</span> name<span style="COLOR: #0000ff">="checkedValues"</span> </span><span style="COLOR: #0000ff">/&gt;</span>
      <span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">input</span><span style="COLOR: #ff0000"> class<span style="COLOR: #0000ff">="button"</span> type<span style="COLOR: #0000ff">="button"</span> value<span style="COLOR: #0000ff">="Submit"</span> onclick<span style="COLOR: #0000ff">="submit()"</span> </span><span style="COLOR: #0000ff">/&gt;</span>

      <span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">input</span><span style="COLOR: #ff0000"> id<span style="COLOR: #0000ff">="check_4273844"</span> onclick<span style="COLOR: #0000ff">="onCheck('4273844')"</span> type<span style="COLOR: #0000ff">="checkbox"</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; name<span style="COLOR: #0000ff">="check_4273844"</span> <strong><font size="4">value<span style="COLOR: #0000ff">="ON"</span></font></strong> </span><span style="COLOR: #0000ff">/&gt;</span>
      ...
      <span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">input</span><span style="COLOR: #ff0000"> id<span style="COLOR: #0000ff">="check_4273843"</span> onclick<span style="COLOR: #0000ff">="onCheck('4273843')"</span> type<span style="COLOR: #0000ff">="checkbox"</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; name<span style="COLOR: #0000ff">="check_4273843"</span> <strong><font size="4">value<span style="COLOR: #0000ff">="ON"</span></font></strong> </span><span style="COLOR: #0000ff">/&gt;</span>
      ...
      <span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">input</span><span style="COLOR: #ff0000"> id<span style="COLOR: #0000ff">="check_4273842"</span> onclick<span style="COLOR: #0000ff">="onCheck('4273842')"</span> type<span style="COLOR: #0000ff">="checkbox"</span> <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; name<span style="COLOR: #0000ff">="check_4273842"</span> <strong><font size="4">value<span style="COLOR: #0000ff">="ON"</span></font></strong> </span><span style="COLOR: #0000ff">/&gt;</span>
      ...
    <span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">form</span><span style="COLOR: #0000ff">&gt;</span>

    Notice the bolded parts.  When the page loads, all the boxes are checked.  If you submit without un-checking and re-checking the box you want, there is no value in the "checkedValues" field.

     

    <font face="Arial" size="2">Huh?&nbsp; value="on" doesn't autocheck a box on the page load.&nbsp; I think you are thinking of</font>

     <span>&lt;</span><span>input</span><span> id<span>="check_4273842"</span> onclick<span>="onCheck('4273842')"</span> type<span>="checkbox"</span> <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; name<span>="check_4273842"</span> <strong><font size="4">checked</font></strong></span><span>/&gt;<br><br><font face="Arial" size="2">Or am I missing something (trust me, its happened before)?</font></span>

  • ole gustie (unregistered) in reply to snoofle
    snoofle:
    Anonymous:
    Anonymous:

    Notice the bolded parts.  When the page loads, all the boxes are checked.  If you submit without un-checking and re-checking the box you want, there is no value in the "checkedValues" field.

    Wait, I was wrong.  That doesn't say "checked" it says "on".  This was so stupid I mentally filled in what he should have been doing instead of what he actually did.

    Wow, that's a lot of work to be so wrong.

    Web-neophyte here - I thought check boxes could only be true/false, or possibly [un]checked. "On" ???

    Check boxes pass whatever is in the "value" attribute to the form action page when they are checked.  If they are not checked, they pass nothing.  If more than one checkboxes have the same name,  all that are checked are passed in a single variable as a comma seperated list.  Basically, the guy/gal wrote a bunch of crap code to do what standard html forms already do.

  • Tukaro (cs)

    It burns.

    It burns. So. Much.

    Please. Someone make it stop!

  • snoofle (cs) in reply to ole gustie
    ole gustie:
    snoofle:
    Anonymous:
    Anonymous:

    Notice the bolded parts.  When the page loads, all the boxes are checked.  If you submit without un-checking and re-checking the box you want, there is no value in the "checkedValues" field.

    Wait, I was wrong.  That doesn't say "checked" it says "on".  This was so stupid I mentally filled in what he should have been doing instead of what he actually did.

    Wow, that's a lot of work to be so wrong.

    Web-neophyte here - I thought check boxes could only be true/false, or possibly [un]checked. "On" ???

    Check boxes pass whatever is in the "value" attribute to the form action page when they are checked.  If they are not checked, they pass nothing.  If more than one checkboxes have the same name,  all that are checked are passed in a single variable as a comma seperated list.  Basically, the guy/gal wrote a bunch of crap code to do what standard html forms already do.

    Thanks - I know just enough about all-things-web to realize how little I know about all-things-web (I tend to stay on the server-side of things - where I know what I'm doing).

  • Marcos (unregistered) in reply to ole gustie

    > If more than one checkboxes have the same name,  all that are checked are passed in a
    > single variable as a comma seperated list. 

    Not true. If more than one checkbox with the same name is checked, then each value is included as a separate name=value pair in the HTTP request.  For instance, if the form has a method of GET and the browser uses the old ampersand separator instead of the newfangled semicolon, a form with three checkboxes named "box" checked might take you to this URL:

    http://foo.com/mySpiffyPage.php?box=yup&box=nope&box=is_too

    How that is presented on the server side depends on the language and API being used.  I've seen ASP's that seem to indicate that VB in an ASP will give you a comma-separated string, though I don't know how you then deal with commas in an individual value.   Most APIs provide a means of getting the list of values as an array;  Perl's CGI::param automatically returns an array in list context if there's more than one value, for instance.  PHP apparently discards all but the last value unless the name ends with [], which isn't even legal HTML.  Of course, there are various add-on solutions to this problem that all involve manually reprocessing the form input...




  • Otto (cs) in reply to ole gustie
    Anonymous:
    Check boxes pass whatever is in the "value" attribute to the form action page when they are checked.  If they are not checked, they pass nothing.  If more than one checkboxes have the same name,  all that are checked are passed in a single variable as a comma seperated list.  Basically, the guy/gal wrote a bunch of crap code to do what standard html forms already do.


    I knew this didn't sound right, so I tried it. What I got in the URL for a GET request looked like this:
    key=test&key=test2

    Now, your language/CGI parser library may change this into something nicer like a comma separated list for you, but the data is actually sent as multiple key=value pairs, only using the same keys.

  • Romeo (cs) in reply to ole gustie
    Anonymous:
    Anonymous:
    Alex Papadimoulis:

    <span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">script</span><span style="color: rgb(255, 0, 0);"> type<span style="color: rgb(0, 0, 255);">="text/javascript"</span></span><span style="color: rgb(0, 0, 255);">&gt;</span> <span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">!--</span><span style="color: rgb(0, 0, 0);"><br><br>function onCheck(id)<br>{<br>&nbsp; checkedValues = document.selecter.checkedValues;<br>&nbsp; checkedBox = document.selecter["check_"+id];<br>&nbsp; <br>&nbsp; if (!checkedBox.checked)<br>&nbsp;&nbsp;&nbsp; checkedValues.value = <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; eval("checkedValues.value.replace(/" +id + ',' + "/g,'')");<br>&nbsp; else<br>&nbsp;&nbsp;&nbsp; <font size="4"><strong>checkedValues.value+=(id+',');</strong><br></font>}<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br>function submit()<br>{<br>&nbsp; document.location.href = 'insert.php?chosen=' + <br>&nbsp;&nbsp;&nbsp;&nbsp; document.selecter.checkedValues.value;<br>&nbsp; return false;<br>}<br><br><br>//--</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">script</span><span style="color: rgb(0, 0, 255);">&gt;</span>

    <span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">form</span><span style="color: rgb(255, 0, 0);"> id<span style="color: rgb(0, 0, 255);">="selecter"</span> name<span style="color: rgb(0, 0, 255);">="selecter"</span></span><span style="color: rgb(0, 0, 255);">&gt;</span>
      <span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">input</span><span style="color: rgb(255, 0, 0);"> type<span style="color: rgb(0, 0, 255);">="hidden"</span> id<span style="color: rgb(0, 0, 255);">="checkedValues"</span> name<span style="color: rgb(0, 0, 255);">="checkedValues"</span> </span><span style="color: rgb(0, 0, 255);">/&gt;</span>
      <span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">input</span><span style="color: rgb(255, 0, 0);"> class<span style="color: rgb(0, 0, 255);">="button"</span> type<span style="color: rgb(0, 0, 255);">="button"</span> value<span style="color: rgb(0, 0, 255);">="Submit"</span> onclick<span style="color: rgb(0, 0, 255);">="submit()"</span> </span><span style="color: rgb(0, 0, 255);">/&gt;</span>

      <span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">input</span><span style="color: rgb(255, 0, 0);"> id<span style="color: rgb(0, 0, 255);">="check_4273844"</span> onclick<span style="color: rgb(0, 0, 255);">="onCheck('4273844')"</span> type<span style="color: rgb(0, 0, 255);">="checkbox"</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; name<span style="color: rgb(0, 0, 255);">="check_4273844"</span> <strong><font size="4">value<span style="color: rgb(0, 0, 255);">="ON"</span></font></strong> </span><span style="color: rgb(0, 0, 255);">/&gt;</span>
      ...
      <span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">input</span><span style="color: rgb(255, 0, 0);"> id<span style="color: rgb(0, 0, 255);">="check_4273843"</span> onclick<span style="color: rgb(0, 0, 255);">="onCheck('4273843')"</span> type<span style="color: rgb(0, 0, 255);">="checkbox"</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; name<span style="color: rgb(0, 0, 255);">="check_4273843"</span> <strong><font size="4">value<span style="color: rgb(0, 0, 255);">="ON"</span></font></strong> </span><span style="color: rgb(0, 0, 255);">/&gt;</span>
      ...
      <span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">input</span><span style="color: rgb(255, 0, 0);"> id<span style="color: rgb(0, 0, 255);">="check_4273842"</span> onclick<span style="color: rgb(0, 0, 255);">="onCheck('4273842')"</span> type<span style="color: rgb(0, 0, 255);">="checkbox"</span> <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; name<span style="color: rgb(0, 0, 255);">="check_4273842"</span> <strong><font size="4">value<span style="color: rgb(0, 0, 255);">="ON"</span></font></strong> </span><span style="color: rgb(0, 0, 255);">/&gt;</span>
      ...
    <span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">form</span><span style="color: rgb(0, 0, 255);">&gt;</span>

    Notice the bolded parts.  When the page loads, all the boxes are checked.  If you submit without un-checking and re-checking the box you want, there is no value in the "checkedValues" field.

     

    <font face="Arial" size="2">Huh?&nbsp; value="on" doesn't autocheck a box on the page load.&nbsp; I think you are thinking of</font>

     <span>&lt;</span><span>input</span><span> id<span>="check_4273842"</span> onclick<span>="onCheck('4273842')"</span> type<span>="checkbox"</span> <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; name<span>="check_4273842"</span> <strong><font size="4">checked</font></strong></span><span>/&gt;<br><br><font face="Arial" size="2">Or am I missing something (trust me, its happened before)?</font></span>



    Sure you're not missing anything.

    WTF on WTF
  • ole gustie (cs) in reply to Otto

    Thanks for the correction.  I guess you learn something new everyday.  I am mainly a client app programmer, so my experience is limited to a couple ASP and coldFusion (gross, I know) hobby sites I help my fellow geeks maintain.

    And the answer to your question is that you learn to keep commas out of the indivdual checkbox values pretty quickly.

  • trippyz (cs) in reply to Tomer Chachamu

    Actually, 'value="ON"' does not mean the box is checked. It just means that if it is checked, the value to send to the server is "ON".

    My eyes are checkered, does that mean they are on?

  • qbolec (cs)
    Alex Papadimoulis:
          
    function submit()
    {
      document.location.href = 'insert.php?chosen=' + 
         document.selecter.checkedValues.value;
      return false;
    }
    

    I'm afraid of:

          
    //insert.php
    mysql_query("INSERT INTO MyOrder (ID) VALUES ($chosen)");
    
  • Volmarias (cs) in reply to qbolec

    Good god, I actually tore at my skin with my fingernails when I read this.

  • cedric (unregistered)

    I could imagine why one would want to reconstruct the querystring and bypass the normal form submission. For instance if there is another javascript function attached to the onSubmit event and for some reason you don't want it to run when you click on that button.

    The eval on the string replace is a bit weird. It looks like a workaround for someone who don't know about the RegExp() object (you can't use variables with the // notation). But you don't really need a regular expression in the first place.

  • CodeRage (cs) in reply to qbolec

    <font face="Courier New" size="2"><font face="Arial">Just to clarify from the PHP people... Is there some reason you wouldn't just use the following ... like I'd do with a Java/Servlet back-end?  Is there some reason building a comma separated string would make things easier in PHP?  I would just use the HttpServletRequest to give me an array of the &quot;chosen&quot; parameters...</font><br><br>&lt;form id=&quot;selecter&quot; name=&quot;selecter&quot; action=&quot;insert.php&quot;&gt;<br>  &lt;input class=&quot;button&quot; type=&quot;submit&quot; value=&quot;Submit&quot; /&gt;<br>  ...<br>  &lt;input type=&quot;checkbox&quot; name=&quot;chosen&quot; value=&quot;4273844&quot; /&gt;<br>  ...<br>  &lt;input type=&quot;checkbox&quot; name=&quot;chosen&quot; value=&quot;4273843&quot; /&gt;<br>  ...<br>  &lt;input type=&quot;checkbox&quot; name=&quot;chosen&quot; value=&quot;4273842&quot; /&gt;<br>  ...<br>&lt;/form&gt;<br><br></font>

  • UTU (unregistered) in reply to Marcos
    Anonymous:
    PHP apparently discards all but the last value unless the name ends with [], which isn't even legal HTML.


    Umm.. how so? If my memory serves me correctly, "name"-attribute of input-elements is of type CDATA, which means "a sequence of characters from the document character set"... so ending a name with [] is just about as allowed in HTML as ... well, just about anything :)
  • smbell (cs) in reply to Volmarias
    Volmarias:
    Good god, I actually tore at my skin with my fingernails when I read this.



    Oooh, I need to get a webcam at my desk too.

  • Kelsey (unregistered) in reply to snoofle

    Young Padewan - checkboxes have three states - true, false, and FileNotFound.
    "On" is indeed the real WTF here.

  • WWWWolf (cs) in reply to qbolec
    qbolec:
    Alex Papadimoulis:
          
    function submit()
    {
      document.location.href = 'insert.php?chosen=' + 
         document.selecter.checkedValues.value;
      return false;
    }
    

    I'm afraid of:

          
    //insert.php
    mysql_query("INSERT INTO MyOrder (ID) VALUES ($chosen)");
    


    Yeah, let's combine a great big web app design flaw with a PHP-specific design flaw: SQL injection annnnnd register_globals... =)
  • Licky Lindsay (unregistered) in reply to ole gustie
    ole gustie:
    I am mainly a client app programmer, so my experience is limited to a couple ASP and coldFusion (gross, I know) hobby sites I help my fellow geeks maintain.


    You would be very surprised (well, no, you wouldn't really) how many people who work with one of those languages every day, and are paid to do so, actually think that the browser sends a comma-separated list.

    captcha: whiskey
  • UTU (unregistered) in reply to CodeRage
    CodeRage:
    <font face="Courier New" size="2"><font face="Arial">Just to clarify from the PHP people... Is there some reason you wouldn't just use the following ... like I'd do with a Java/Servlet back-end?&nbsp; Is there some reason building a comma separated string would make things easier in PHP?&nbsp; I would just use the HttpServletRequest to give me an array of the "chosen" parameters...</font><br><br>&lt;form id="selecter" name="selecter" action="insert.php"&gt;<br>&nbsp; &lt;input class="button" type="submit" value="Submit" /&gt;<br>&nbsp; ...<br>&nbsp; &lt;input type="checkbox" name="chosen" value="4273844" /&gt;<br>&nbsp; ...<br>&nbsp; &lt;input type="checkbox" name="chosen" value="4273843" /&gt;<br>&nbsp; ...<br>&nbsp; &lt;input type="checkbox" name="chosen" value="4273842" /&gt;<br>&nbsp; ...<br>&lt;/form&gt;<br><br></font>


    Yes, there is a reason. See http://fi2.php.net/manual/en/faq.html.php#faq.html.arrays for explanation. However, if your example were like 'name="chosen[]"', there would be no problem; we'd have array $_GET["chosen"] to use :)
  • Licky Lindsay (unregistered) in reply to UTU
    Anonymous:
    Anonymous:
    PHP apparently discards all but the last value unless the name ends with [], which isn't even legal HTML.


    Umm.. how so? If my memory serves me correctly, "name"-attribute of input-elements is of type CDATA, which means "a sequence of characters from the document character set"... so ending a name with [] is just about as allowed in HTML as ... well, just about anything :)


    PHP isn't the only "framework" that uses that kind of thing either. Struts, for instance, uses the hell out of it.

    Captcha: error
  • Ann Coulter (unregistered) in reply to ole gustie
    Anonymous:
    Anonymous:
    Alex Papadimoulis:

    <span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">script</span><span style="color: rgb(255, 0, 0);"> type<span style="color: rgb(0, 0, 255);">="text/javascript"</span></span><span style="color: rgb(0, 0, 255);">&gt;</span> <span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">!--</span><span style="color: rgb(0, 0, 0);"><br><br>function onCheck(id)<br>{<br>&nbsp; checkedValues = document.selecter.checkedValues;<br>&nbsp; checkedBox = document.selecter["check_"+id];<br>&nbsp; <br>&nbsp; if (!checkedBox.checked)<br>&nbsp;&nbsp;&nbsp; checkedValues.value = <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; eval("checkedValues.value.replace(/" +id + ',' + "/g,'')");<br>&nbsp; else<br>&nbsp;&nbsp;&nbsp; <font size="4"><strong>checkedValues.value+=(id+',');</strong><br></font>}<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br>function submit()<br>{<br>&nbsp; document.location.href = 'insert.php?chosen=' + <br>&nbsp;&nbsp;&nbsp;&nbsp; document.selecter.checkedValues.value;<br>&nbsp; return false;<br>}<br><br><br>//--</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">script</span><span style="color: rgb(0, 0, 255);">&gt;</span>

    <span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">form</span><span style="color: rgb(255, 0, 0);"> id<span style="color: rgb(0, 0, 255);">="selecter"</span> name<span style="color: rgb(0, 0, 255);">="selecter"</span></span><span style="color: rgb(0, 0, 255);">&gt;</span>
      <span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">input</span><span style="color: rgb(255, 0, 0);"> type<span style="color: rgb(0, 0, 255);">="hidden"</span> id<span style="color: rgb(0, 0, 255);">="checkedValues"</span> name<span style="color: rgb(0, 0, 255);">="checkedValues"</span> </span><span style="color: rgb(0, 0, 255);">/&gt;</span>
      <span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">input</span><span style="color: rgb(255, 0, 0);"> class<span style="color: rgb(0, 0, 255);">="button"</span> type<span style="color: rgb(0, 0, 255);">="button"</span> value<span style="color: rgb(0, 0, 255);">="Submit"</span> onclick<span style="color: rgb(0, 0, 255);">="submit()"</span> </span><span style="color: rgb(0, 0, 255);">/&gt;</span>

      <span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">input</span><span style="color: rgb(255, 0, 0);"> id<span style="color: rgb(0, 0, 255);">="check_4273844"</span> onclick<span style="color: rgb(0, 0, 255);">="onCheck('4273844')"</span> type<span style="color: rgb(0, 0, 255);">="checkbox"</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; name<span style="color: rgb(0, 0, 255);">="check_4273844"</span> <strong><font size="4">value<span style="color: rgb(0, 0, 255);">="ON"</span></font></strong> </span><span style="color: rgb(0, 0, 255);">/&gt;</span>
      ...
      <span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">input</span><span style="color: rgb(255, 0, 0);"> id<span style="color: rgb(0, 0, 255);">="check_4273843"</span> onclick<span style="color: rgb(0, 0, 255);">="onCheck('4273843')"</span> type<span style="color: rgb(0, 0, 255);">="checkbox"</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; name<span style="color: rgb(0, 0, 255);">="check_4273843"</span> <strong><font size="4">value<span style="color: rgb(0, 0, 255);">="ON"</span></font></strong> </span><span style="color: rgb(0, 0, 255);">/&gt;</span>
      ...
      <span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">input</span><span style="color: rgb(255, 0, 0);"> id<span style="color: rgb(0, 0, 255);">="check_4273842"</span> onclick<span style="color: rgb(0, 0, 255);">="onCheck('4273842')"</span> type<span style="color: rgb(0, 0, 255);">="checkbox"</span> <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; name<span style="color: rgb(0, 0, 255);">="check_4273842"</span> <strong><font size="4">value<span style="color: rgb(0, 0, 255);">="ON"</span></font></strong> </span><span style="color: rgb(0, 0, 255);">/&gt;</span>
      ...
    <span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">form</span><span style="color: rgb(0, 0, 255);">&gt;</span>

    Notice the bolded parts.  When the page loads, all the boxes are checked.  If you submit without un-checking and re-checking the box you want, there is no value in the "checkedValues" field.

     

    <font face="Arial" size="2">Huh?&nbsp; value="on" doesn't autocheck a box on the page load.&nbsp; I think you are thinking of</font>

     <span>&lt;</span><span>input</span><span> id<span>="check_4273842"</span> onclick<span>="onCheck('4273842')"</span> type<span>="checkbox"</span> <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; name<span>="check_4273842"</span> <strong><font size="4">checked</font></strong></span><span>/&gt;<br><br><font face="Arial" size="2">Or am I missing something (trust me, its happened before)?</font></span>



    Well, if you're going to use xhtml you should make it

    <span>&lt;</span><span>input</span><span> id<span>="check_4273842"</span> onclick<span>="onCheck('4273842')"</span> type<span>="checkbox"</span> <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; name<span>="check_4273842"</span> <strong><font size="4">checked</font></strong></span><span><b>="</b></span><span><strong><font size="4">checked</font></strong></span><span></span><span><b>"</b>/&gt;</span>
  • WHO WANTS TO KNOW? (unregistered) in reply to UTU

    Actually, PHP even has a design flaw that makes this CHILDS PLAY!  Then again, the new PROPER way isn't much harder.  PHP was built from the ground up to work with this stuff.

    Steve

  • ammoQ (cs) in reply to UTU
    Anonymous:

    Yes, there is a reason. See http://fi2.php.net/manual/en/faq.html.php#faq.html.arrays for explanation. However, if your example were like 'name="chosen[]"', there would be no problem; we'd have array $_GET["chosen"] to use :)


    Hard to believe. How can a programming language especially made for web programming require such client-visible workarounds to accomplish such basic tasks? Even Oracle's Web toolkit (web programming in PL/SQL, introduced around '99) does it better.
  • ammoQ (cs) in reply to Licky Lindsay
    Anonymous:

    PHP isn't the only "framework" that uses that kind of thing either. Struts, for instance, uses the hell out of it.

    Maybe, but struts has a higher level of abstraction.
  • Rich (unregistered) in reply to UTU

    PHP will only accept arrays of inputs if the input is named with a [] suffix. This is a pet peeve of mine, I feel that a proper server side web scripting language should be able to handle whatever form data is sent at it sanely.

    If I remember ASP correctly (it's been a while), if you read the input directly, you get a comma separated list but you can also read the input as an array [Don't remember how but it's fairly simple]. I think the comma separated list is an awful holdover from htx/idc of the original IIS (Makes me feel queasy just thinking about it).

    Rich

  • savar (cs) in reply to ammoQ
    ammoQ:


    Hard to believe. How can a programming language especially made for web programming require such client-visible workarounds to accomplish such basic tasks? Even Oracle's Web toolkit (web programming in PL/SQL, introduced around '99) does it better.


    It's not a work-around, it's just how things are done. PHP isn't an amazingly clever language, but what's wrong with using [] to return an array? It's no more client-visible than using the same name without [] for each element.
  • NZ'er (unregistered) in reply to UTU
    Anonymous:
    CodeRage:
    <font face="Courier New" size="2"><font face="Arial">Just to clarify from the PHP people... Is there some reason you wouldn't just use the following ... like I'd do with a Java/Servlet back-end?&nbsp; Is there some reason building a comma separated string would make things easier in PHP?&nbsp; I would just use the HttpServletRequest to give me an array of the "chosen" parameters...</font><br><br>&lt;form id="selecter" name="selecter" action="insert.php"&gt;<br>&nbsp; &lt;input class="button" type="submit" value="Submit" /&gt;<br>&nbsp; ...<br>&nbsp; &lt;input type="checkbox" name="chosen" value="4273844" /&gt;<br>&nbsp; ...<br>&nbsp; &lt;input type="checkbox" name="chosen" value="4273843" /&gt;<br>&nbsp; ...<br>&nbsp; &lt;input type="checkbox" name="chosen" value="4273842" /&gt;<br>&nbsp; ...<br>&lt;/form&gt;<br><br></font>


    Yes, there is a reason. See http://fi2.php.net/manual/en/faq.html.php#faq.html.arrays for explanation. However, if your example were like 'name="chosen[]"', there would be no problem; we'd have array $_GET["chosen"] to use :)


    Cheers for this!  I am relitivly new to PHP programming and was trying to do somthing similar (trying to get PHP to accept an array of inputs, not the horrible javascript thing) and ran out of energy to Google it and find out. So this just saved me some time.  I have done similar things in perl and PL/SQL and both seem simpler to me but I guess it is just a quirk of the language.

Leave a comment on “A New Type of Formation”

Log In or post as a guest

Replying to comment #:

« Return to Article