Javascript map code
Hi All,
I have the below code which works fine
event.value = event.value.toUpperCase(); if (event.value=="PACIFIC EXPLORER") this.getField("GRT").value="77441"; else if (event.value=="PACIFIC ADVENTURE") this.getField("GRT").value="108865"; else if (event.value=="CORAL PRINCESS") this.getField("GRT").value="91627"; else if (event.value=="CARNIVAL SPLENDOR") this.getField("GRT").value="113562"; else if (event.value=="MAJESTIC PRINCESS") this.getField("GRT").value="144216"; else if (event.value=="CELEBRITY ECLIPSE") this.getField("GRT").value="121878"; else if (event.value=="CELEBRITY EDGE") this.getField("GRT").value="130818"; else if ((event.value=="OVATION OF THE SEAS")||(event.value=="QUANTUM OF THE SEAS")) this.getField("GRT").value="168666"; else if (event.value=="NOORDAM") this.getField("GRT").value="82897"; else if (event.value=="NORWEGIAN SPIRIT") this.getField("GRT").value="75904"; else if (event.value=="PACIFIC ENCOUNTER") this.getField("GRT").value="108977"; else if (event.value=="PIONEER") this.getField("GRT").value="17094"; else if (event.value=="ICS RELIANCE") this.getField("GRT").value="4386"; else this.getField("GRT").value="";
but its a bit long winded and if I need to add vessels then its not quite as straight forward as I would like. some research else where on the web has led me to the following
const shipGRTMap = new Map([
["PACIFIC EXPLORER", "77441"],
["PACIFIC ADVENTURE", "108865"],
["CORAL PRINCESS", "91627"],
["CARNIVAL SPLENDOR", "113562"],
["MAJESTIC PRINCESS", "144216"],
["CELEBRITY ECLIPSE", "121878"],
["CELEBRITY EDGE", "130818"],
["OVATION OF THE SEAS", "168666"],
["QUANTUM OF THE SEAS", "168666"],
["NOORDAM", "82897"],
["NORWEGIAN SPIRIT", "75904"],
["PACIFIC ENCOUNTER", "108977"],
["PIONEER", "17094"],
["ICS RELIANCE", "4386"]
]);
function updateGRTValue(event) {
var shipName = this.getField("VESSEL").value;
var grtField = this.getField("GRT");
var grtValue = shipGRTMap.get(shipName);
grtField.value = grtValue !== undefined ? grtValue : "";
}
but for some reason it does not work!
Is it completely wrong / not approariate for Adobe PDF documents or something else.
Thanks for your help.
