Me han encargado convertir los formularios del sistema judicial para el que trabajo en archivos PDF rellenables. Se me pidió que hiciera que el campo "dirección" se completara automáticamente según la opción seleccionada en la lista desplegable "Sala del tribunal". No sé nada sobre codificación, así que busqué en foros hasta que encontré un tutorial que contenía este código.
// Place all prepopulation data into a single data structure var DeptData = { Accounting:{ contact: "Steala Damuni", email: "accounting@mycomp.com", deptnum: "cmp1234" }, Engineering:{ contact: "Frank N. Stien", email: "engineering@mycomp.com", deptnum: "eng1234" }, Marketing :{ contact: "Shelly Oughtbuks", email: "marketing@mycomp.com", deptnum: "mkt1234" }, ITSupport:{ contact: "Goah Wei", email: "it@mycomp.com", deptnum: "its1234" }}; function SetFieldValues(cDeptName) { this.getField("DeptContact").value = DeptData[cDeptName].contact; this.getField("DeptEmail").value = DeptData[cDeptName].email; this.getField("DeptNumber").value = DeptData[cDeptName].deptnum; }Intenté cambiar los nombres de los campos para que coincidieran con mi formulario y obtuve esto
var DeptData = { South Division Dept. 1:{ address: "20520 68th Ave. W. Lynnwood WA 98036"}, South Division Dept. 2:{ address: "20520 68th Ave W Lynnwood WA 98036"}, South Division Dept. 3:{ address: "20520 68th Ave. W. Lynnwood WA 98036"}, South Division Dept. 4:{ address: "20520 68th Ave. W. Lynnwood WA 98036"}, Cascade Division Dept. 1:{ address: "415 E Burke Ave. Arlington WA 98223"}, Cascade Division Dept. 2:{ address: "415 E Burke Ave. Arlington WA 98223"}, Evergreen Division Dept. 1:{ address: "14414 179th Ave SE Monroe WA 98272"}, Evergreen Division Dept. 2:{ address: "14414 179th Ave SE Monroe WA 98272"}, Everett Division Courtroom 3A:{ address: "3000 Rockefeller Ave Everett WA 98201"}, Everett Division Courtroom 3B:{ address: "3000 Rockefeller Ave Everett WA 98201"}, Everett Division Courtroom 3C:{ address: "3000 Rockefeller Ave Everett WA 98201" }}; function SetFieldValues(cCourtroom) { this.getField("address").value = DeptData[cCourtroom].address; }La cuestión es que sigue arrojando un error, "SyntaxError: falta: después de la propiedad id 1: en la línea 2"
Sus claves de objeto tienen espacios, debe ponerlos entre comillas como esta:
var DeptData = { "South Division Dept. 1":{ address: "20520 68th Ave. W. Lynnwood WA 98036"}, "South Division Dept. 2":{ address: "20520 68th Ave W Lynnwood WA 98036"}, "South Division Dept. 3":{ address: "20520 68th Ave. W. Lynnwood WA 98036"}, "South Division Dept. 4":{ address: "20520 68th Ave. W. Lynnwood WA 98036"}, "Cascade Division Dept. 1":{ address: "415 E Burke Ave. Arlington WA 98223"}, "Cascade Division Dept. 2":{ address: "415 E Burke Ave. Arlington WA 98223"}, "Evergreen Division Dept. 1":{ address: "14414 179th Ave SE Monroe WA 98272"}, "Evergreen Division Dept. 2":{ address: "14414 179th Ave SE Monroe WA 98272"}, "Everett Division Courtroom 3A":{ address: "3000 Rockefeller Ave Everett WA 98201"}, "Everett Division Courtroom 3B":{ address: "3000 Rockefeller Ave Everett WA 98201"}, "Everett Division Courtroom 3C":{ address: "3000 Rockefeller Ave Everett WA 98201" }};