Search code examples
javascriptadobe

Adobe JavaScipt


Hello I would need help with some JavaScript not knowing much about it.

On an Adobe Acrobat DC file during a form I offer a 500 € pack including 3 options (the first 3 checkboxes by default) with the possibility of having an additional option free. We therefore offer 5 other options with a price of 250 €. My goal is that when a customer ticks his first box, it will be free and the amount of € 500 will not change, but if he ticks additional boxes, the price will be € 250. In summary I would like the first box checked to be free (not knowing the option he will choose) and that the boxes checked then add € 250 to € 500 (base price) in the “TOTAL” box. my checkboxes naming this: A, B, C, D, E.

enter image description here


Solution

  • A starting point... I use a global function, you have to check and add your own logic.

     form1::initialize - (JavaScript, client)
    xfa.form.form1.form.Total.rawValue = 500;
    global.addTo = function (val) {
        xfa.form.form1.form.Total.rawValue = xfa.form.form1.form.Total.rawValue = 500 + val;
        if (xfa.form.form1.form.Total.rawValue < 500) {
            xfa.form.form1.form.Total.rawValue = 500;
        }
    }
    
     form1.form.Option1::change - (JavaScript, client)
    app.alert('form1.form.Option1::change');
    if (xfa.form.form1.form.Option1.rawValue) {
        app.alert('Checked');
        global.addTo(250);
    } else {
        global.addTo(-250);
    }
    
     form1.form.Option2::change - (JavaScript, client)
    app.alert('form1.form.Option2::change');
    if (xfa.form.form1.form.Option2.rawValue) {
        app.alert('Checked');
        global.addTo(250);
    } else {
        global.addTo(-250);
    }
    
     form1.form.Option3::change - (JavaScript, client)
    app.alert('form1.form.Option3::change');
    if (xfa.form.form1.form.Option3.rawValue) {
        app.alert('Checked');
        global.addTo(250);
    } else {
        global.addTo(-250);
    }