Sometimes it’s necessary to modify an input form element when a user clicks on that element. In some cases, the form element can contain information regarding what information is appropriate, or what format is expected. The most common example is showing “mm/dd/yyyy” in a text-based date field and automatically removing that information when a user clicks on the field.
Continue readingCategory Archives: Javascript
Javascript Benchmarking with JSBenchtest
Javascript benchmarking couldn’t be easier. With this webpage you can input any Javascript code and test how fast it is. The webpage will automatically call your code for 1,000,000 iterations and report the total amount of time that it took to execute. It will even output a variable that you can use for debugging. You can now test an algorithm, make a modification, and test again to see if the modification helped the execution time.
Click here to benchmark some code.
Continue readingSwitch vs If – Which is faster?
In programming there are two different methods that people use to test variables that have a number of different values. One method is to use the If statement and define blocks of code to perform. The other common method is to use a switch statement and list all possible values, perhaps including a default value, and perform some process inside the appropriate section of code.
Continue readingJavascript: Flattening a Multidimensional Array
A friend had asked me about converting a 2-dimensional array into a flat 1-dimensional array. In array form this would be (written as was provided to me):
in = [1,"2",[3,"4"]];
out = [1,"2",3,"4"]; //this is what he wanted out.
Continue reading Where did CSS and JavaScript go wrong?
Ahhhhhhhh!!! That’s me pulling out my hair every time I start working with divs, CSS, and the DOM’s innerHTML property using JavaScript. I can never figure out if I’m doing something wrong or if someone somewhere made a huge mistake when they made innerHTML.
Continue reading
Creating a PHP/MySQL/JSON Comment System
I had developed a PHP comment system based on the code from the Advanced Comment System sample from HotScripts. This code worked well, but it wasn’t the most dynamic and needed to be improved.
Continue reading