Help with JavaScript in a Form
i creating form in acrobat needs little javascript, don't know javascript appreciated.
in form there separate price fields , field automatically fills in average price of them. problem not 4 price fields going filled out in every instance ruins average. need script average price fields have value.
i thinking create invisible field state
if (price) > 0 set value 1 (what in javascript?)
i each of 4 price fields in invisible field count them , use sum divide total cost average.
thanks in advance help!
in form there separate price fields , field automatically fills in average price of them. problem not 4 price fields going filled out in every instance ruins average. need script average price fields have value.
i thinking create invisible field state
if (price) > 0 set value 1 (what in javascript?)
i each of 4 price fields in invisible field count them , use sum divide total cost average.
thanks in advance help!
you don't need use hidden fields. use following custom calculation script of average price field:
this code assumes field names "price1", "price2"..."price4", fields numeric, , used acrobat create fields, opposed livecycle designer. note if field has value of zero, counted field value.
george
// initialize variables
var cur_val; // variable hold current field value
var sum = 0; // sum of field values
var num = 0; // number of fields values
// loop through price fields
for (var = 0; < 4; i++) {
// field value
curr_val = getfield("price" + (i + 1)).valueasstring;
// if field not empty, add sum , increment counter
if (curr_val != "") {
sum += +curr_val; // add current value sum
num++; // increment counter
}
}
// if there @ least 1 field value
// set field value equal average
if (num) event.value = sum/num;
// otherwise, blank field
else event.value = "";
this code assumes field names "price1", "price2"..."price4", fields numeric, , used acrobat create fields, opposed livecycle designer. note if field has value of zero, counted field value.
george
More discussions in Acrobat Macintosh (read-only)
adobe
Comments
Post a Comment