I hadn't previously noticed the chmod calculation box at the bottom of the tutorial page Deb mentioned. Rather cool. I took a peek at the source code, mostly out of curiosity, and was a bit surprised at the wordiness of it. For anyone looking to use something similar, the JavaScript can be reduced by about 75% by changing it to:
Code Sample: <script language="JavaScript">
<!--
function calculator(user) {
var field4 = user + "4";
var field2 = user + "2";
var field1 = user + "1";
var total = "t_" + user;
var number = 0;
if (document.chmod[field4].checked == true) { number += 4; }
if (document.chmod[field2].checked == true) { number += 2; }
if (document.chmod[field1].checked == true) { number += 1; }
if (number == 0) { number = ""; }
document.chmod[total].value = number;
}
//-->
</script> |
|
and changing the HTML form elements from:
onclick="calculator('owner', 4)"
...
to:
onclick="calculator('owner')"
onclick="calculator('group')"
onclick="calculator('other')"
Reduce, Reuse, Recycle...
Dan
- the things we do at 3am when it's too hot to work during the day...