July 11, 2008
I came across this code today, and it took me a second to figure out what it was doing: strSortOrder = document.getElementById("ad").options[document.getElementById("ad").selectedIndex].value; To break it down, it locates a Select control on the page (FindElementById), finds the element again and gets its selected value's index (selectedIndex), and sets the variable to the value of the option at the specified index (options[index].value). There is a jQuery plugin that really simplifies this process. Using jquery.selectboxes.js, the code now is as simple as this: strSortOrder = $("#ad").selectedValues(); This code now does the same thing, but it is also easy to read, and understand. It shortened from 86 characters to 26, and now requires no explanation. There are many different cases where jQuery can simplify the code.
jQuery = Simplification
July 11, 2008
I came across this code today, and it took me a second to figure out what it was doing: strSortOrder = document.getElementById("ad").options[document.getElementById("ad").selectedIndex].value; To break it down, it locates a Select control on the page (FindElementById), finds the element again and gets its selected value's index (selectedIndex), and sets the variable to the value of the option at the specified index (options[index].value). There is a jQuery plugin that really simplifies this process. Using jquery.selectboxes.js, the code now is as simple as this: strSortOrder = $("#ad").selectedValues(); This code now does the same thing, but it is also easy to read, and understand. It shortened from 86 characters to 26, and now requires no explanation. There are many different cases where jQuery can simplify the code.
July 7, 2008
I'm sure most of the ClearBasic brainiacs already know this (and I may have at one point), but the parameter to App.ShowSolution is a record of type "workaround", not a record of type "probdesc". I probably knew this at one time, but its been a long time since I've done ClearBasic coding. I'm blogging this so that I can find it again in the future, with Google's help, of course. If you call App.ShowSolution with a probdesc record, you get this ever-so-helpful pile of joy: Cannot map specific relation (type 1 with relation -3). Uh, yeah. Thanks. No, really. That was a helpful message. I'm in awe of your ability to render something so utterly useless. Freakin' programmers. Working code example: Sub ShowObject(objectType As String, idNumber As String) If objectType = "solution" Then objectType = "probdesc" …