javascript

access key + value in hash or array

SOFTWARE: javascript

for (var i in myArray) { alert('key is: ' + i + ', value is: ' + myArray[i]);

Awesome stuff from http://www.mojavelinux.com/articles/javascript_hashes.html

var myArray = new Array();
myArray['one'] = 1;
myArray['two'] = 2;
myArray['three'] = 3;

for (var i in myArray) {
alert('key is: ' + i + ', value is: ' + myArray[i]);
}

You can also set up an array with this handy syntax:

var actValues = {
'one': 1,
'two': 2,
'three': 3
}

Note that if you space it and leave a trailing comma after the last entry, IE7 will choke.

MORE INFO: http://www.mojavelinux.com/articles/javascript_hashes.html

Apply Focus to Something

You can apply focus on page load with this added inside the opening BODY tag:

onLoad="self.focus();document.Name_Of_Form.Name_Of_Field.focus()"

but if you're working with templates and your BODY tag is in the template and you don't want that JS on every page, you can just add your JS directly to a page by placing directly AFTER the element you're working with:

[form is here] then...

<script type="text/javascript">
    function applyfocus() {
        self.focus();document.Name_Of_Form.Name_Of_Field.focus();
    }
    applyfocus();
</script>
Comments