Adding/Subtracting Current Value from Form Field
I'd like to change the current values of 12 numerical text fields on the mouseup of a button. I've tried defining variables and saying the variable value equals itself + or - the change, creating a temporary variable and assigning a value to it and systematically changing the values of each, creating functions, etc. Here's my script worksheet with everything I've tried. the last has a document level function. The simple "variable = variable + number" almost works but it only seems to apply the math to the last line and not the other three...lines 17-20 do this...ignore all the note markup when analyzing code, that's only so I didn't have to delete things that didn't work.
What am I missing?
/*
var j9opi1 = this.getField("j9-opi1").value;
var j9opi2 = this.getField("j9-opi2").value;
var j9opi3 = this.getField("j9-opi3").value;
var j9opi4 = this.getField("j9-opi4").value;
var j9opi5 = this.getField("j9-opi5").value;
var j9opi6 = this.getField("j9-opi6").value;
var j9opi7 = this.getField("j9-opi7").value;
var j9opi8 = this.getField("j9-opi8").value;
var j9opi9 = this.getField("j9-opi9").value;
var j9opi10 = this.getField("j9-opi10").value;
var j9opi11 = this.getField("j9-opi11").value;
var j9opi12 = this.getField("j9-opi12").value;
j9opi2 = j9opi2 - 9;
j9opi3 = j9opi3 - 9;
j9opi4 = j9opi4 + 2;
j9opi5 = j9opi5 - 4;
*/
var f1 = this.getField("j9-opi1");
var f2 = this.getField("j9-opi2");
var f3 = this.getField("j9-opi3");
var f4 = this.getField("j9-opi4");
var f5 = this.getField("j9-opi5");
var f6 = this.getField("j9-opi6");
var f7 = this.getField("j9-opi7");
var f8 = this.getField("j9-opi8");
var f9 = this.getField("j9-opi9");
var f10 = this.getField("j9-opi10");
var f11 = this.getField("j9-opi11");
var f12 = this.getField("j9-opi12");
var j9pins = this.getField("j9-pins1");
var j9out = this.getField("j9-out1");
var temp = 0;
/*
j9pins.display = display.hidden;
j9out.display = display.visible;
temp.value = f11;
f11 = f5;
f5 = f9;
f9 = f8;
f8 = f7;
f7 = f3;
f3 = f12;
f12 = f6;
f6 = f10;
f10 = f4;
f4 = f2;
f2 = temp.value;
function sortOut(a,b) {
a.value = b.value;
}
//temp = f2.value;
sortOut(f2,f4);
sortOut(f4,f10);
sortOut(f10,f6);
sortOut(f6,f12);
sortOut(f12,f3);
sortOut(f3,f7);
sortOut(f7,f8);
sortOut(f8,f9);
sortOut(f9,f5);
sortOut(f5,f11);
//f11.value = temp;
*/
/*
((f2.value = f2.value - 9) &&
(f3.value = f3.value - 9) &&
(f4.value = f4.value + 2) &&
(f5.value = f5.value - 4));
var f2a = f2.valueAsString;
var f3a = f3.valueAsString;
var f4a = f3.valueAsString;
var f5a = f4.valueAsString;
sortOutS(f2,9);
sortOutS(f3,9);
sortOutA(f4,2);
sortOutS(f5,4);
*/
I'm currently developing an electrical schematic that has an output connector with 12 pins. The pins and outputs are not in chronological order from each other, so a feature has been requested to allow the end user to sort by either pin or by output. There isn't a pattern.
Furthermore, the form has 23 outputs that can be grouped in groups of 20. (1-23, 21,43, etc up to 203). For that, I wrote a script to change the value of each field by by creating a variable with a value that adds to the default value as a custom keystroke script.
var out = this.getField("outputs");
var add = 0;
if(out.value == "1-23") {
add = 0;
}
else if(out.value == "21-43") {
add = 20;
}
else if(out.value == "41-63") {
add = 40;
}
else if(out.value == "61-83") {
add = 60;
}
else if(out.value == "81-103") {
add = 80;
}
else if(out.value == "101-123") {
add = 100;
}
else if(out.value == "121-143") {
add = 120;
}
else if(out.value == "141-163") {
add = 140;
}
else if(out.value == "161-183") {
add = 160;
}
else if(out.value == "181-203") {
add = 180;
}
for (var i = 0; i < this.numFields; i++) {
var f = this.getField(this.getNthFieldName(i));
var reg = /.+-opi\d+/;
if(f.name.match(reg)) {
f.value = f.defaultValue + add;
}
}
