Disable All Links Within DIV

This JavaScript function will disable all links within the specified DIV by setting the link object to ‘disabled’ as well as removing the ‘onclick’ and ‘href’ attributes. This is a useful JavaScript function for form submissions since it will help prevent the user from clicking another link while an action is pending.

function DisableAllDIVLinks(DivId) {
  var div = document.getElementById(DivId);
  var anchorList = div.getElementsByTagName('a');

  for(var i = 0; i < anchorList.length; i++) {
    anchorList[i].disabled = true;
    anchorList[i].onclick = '';

Using NextGEN Gallery and Auto Thickbox

After many attempts, I finally have the NextGEN Gallery plugin working together with the Auto Thickbox plugin. I use NextGEN Gallery for the Photo Gallery pages on this site because I like the way it manages photo albums and galleries. However, I also like to include images in posts outside of NextGEN Gallery’s control. I wanted all of the clickable images on the site to be displayed using a Thickbox, e.g. the fancy popup frame that shows a larger image and the photo title. NextGEN Gallery can handle the images in its albums, but any images in regular posts would just display the raw image file, i.e. no Thickbox frame or site wrapper. When I added the Auto Thickbox plugin to the site, NextGEN Gallery and Auto Thickbox were in conflict since they were both attempting to add a Thickbox to the album images. To get both plugins to work together, I did the following:

Within NextGen Gallery Administration:
Under Gallery -> Options -> Effects:
Set JavaScript Thumbnail effect:  Custom
Link Code line:  class="thickbox" rel="%GALLERY_NAME% nobox"

The “nobox” option instructs NextGEN Gallery not to add the Thickbox code. This then allows Auto Thickbox to add Thickbox code for all clickable images (including images in NextGEN Gallery managed albums). No more conflict!

Round Double To Nearest Hundredth

Here are a few ways to round a double in Java to the nearest integer, tenths, hundredths, or thousandths decimal place.

UPDATE #1: A reader commented that the code was not working for tenths, hundredths, and thousandths. It has been corrected, as suggested, by adding a decimal point to the multipliers and divisors.

UPDATE #2: A reader commented that the code was only working for positive numbers. It has been corrected to handle both positive and negative numbers (and zero, too).

Such simple code, yet two errors were identified by readers. Shame on me for not fully testing the code before posting. Feel free to let me know if you find any other scenarios that don’t work as expected.

double x = 0.0d;
double y = 0.0d;

// Double rounded to the nearest integer.
y = (int) (x + ((x < 0.0) ? -0.5 : 0.5));

// Double rounded to the nearest tenth.
y = ((int) ((x * 10.0) + ((x < 0.0) ? -0.5 : 0.5))) / 10.0;

// Double rounded to the nearest hundredth.
y = ((int) ((x * 100.0) + ((x < 0.0) ? -0.5 : 0.5))) / 100.0;

// Double rounded to the nearest thousandth.
y = ((int) ((x * 1000.0) + ((x < 0.0) ? -0.5 : 0.5))) / 1000.0;