Javascript Loop to Assign Values to Fields
I have 4 fields that are named prc10, prc20, prc30, and prc40, along with a couple of ther fields. I have a button that when pressed is supposed to loop through all the fields in the form, and if the field's name starts with "prc" it assigns the number after the "prc" as the value to the field.
Here's the code I have assigned to the button:
for(i=0;i<numFields;i++){
var strname = getField(getNthFieldName(i)).name;
var prcField = this.getField(strname);
if (strname.startsWith("prc")) {
prcField.value = strname.substring(3);
}
}When I press the button, it assigns the value of the first prc field to 10, but leaves the other 3 empty. If I press the button again it assigns the value of 20 to the second field and leaves the next two empty. So I need to press the button 4 times to get it to assign values to the 4 fields.
I commented out the line where the value is getting assigned to the field and outputting strname.substring(3) to the console to make sure that's working and after clicking the button once, it outputs 10, 20, 30, 40.
Any ideas why it doesn't assign all the fields with one click?
