With so many repeated actions I would look at using functions for many of the processes. An example of a document level function that gets field objects and reports issues when accessing the field.
function GetField(cName) {
var oField = this.getField(cName);
if(oField == null) app.alert("Error accessing field named "+ cName, 0, 0);
return oField;
}
One could use this like:
var p_name = event.target.name;
var ram = p_name.slice(1,2);
console.println("page number:" +(ram));
var mar = ram - 1;
console.println("page number -1:" +(mar));
var myField = GetField("P" + mar + ".mytemplate." + "DOB");
console.show();console.clear():
console.println("DOB on page " + mar + " is "+ myField.value);
I would consider also using the slice method to get the "P#" prefix and template names.
var cFieldName = event.target.name;
var aFieldName = cFieldName.split(".");
console.show(); console.clear();
console.println("Field name: " + cFieldName);
for(i = 0; i < aFieldName.length; i++) {
console.println(i + ": " + aFieldName[i]);
}
console.println("P# & template name: " + aFieldName[0] + "." + aFieldName[1]);