Topic: Custom javascript file is preventing map showing correctly
Hi,
Similar to this previous post (http://forums.nbn.org.uk/viewtopic.php?id=5618) which wasn't resolved, I want to add some custom javascript that runs when certain species are selected.
I found this documentation (http://indicia-docs.readthedocs.io/en/l … ality.html) and I think I am almost there.
My form is node/6616 (page category: data entry forms; page type: enter single record or list of records) and so I have made a file /sites/all/modules/iform/client_helpers/prebuilt_forms/js/node.6616.js with the javascript. It just sets the sensitivity value if the species field is one of several specified values. This works nicely. However, it prevents the map from showing properly. The space for the map is there but no layers show. If I remove the js file, the map works again. Firebug doesn't indicate any particular errors but when I compare the Net JavaScript output when the node.6616.js file does/does not exist I see that some other js files are not called when my node.6616.js file does exist (e.g. GET map.js). So it seems that the node.6616.js file is preventing other js files being called.
In node.6616.js the javascript is called when the window loads. Is this the problem and if so, how/when should it be called?
Thanks in advance for any suggestions, Alice
The js file content is:
window.onload = function () {
/* event listener */
document.getElementsByName("occurrence:taxa_taxon_list_id:taxon")[0].addEventListener('blur', doBlur);
function doBlur(){
if ((this.value=="Bitis peringueyi" || this.value=="Python anchietae" || this.value=="Anchieta's Dwarf Python" || this.value=="Bitis schneideri" || this.value=="Namaqua Dwarf Adder")) {
alert('This species is sensitive. The coordinates will be set to blur to 100km to protect its location.');
document.getElementById("sensitive-checkbox").checked = true;
var element = document.getElementById('sensitive-blur');
element.value = 100000;
element.disabled=false;
var element2 = document.getElementById('sensitivity-controls');
element2.style.opacity = "1";
}
}
}