• Resolved chandlerlozza

    (@chandlerlozza)


    Trying to use the calculation form with document.getElementById and I am unable to run the javascript to do an if statement over the data. After lots of testing I think the issue is the document.getElementById(“risk”).value as I think it is not being picked up to be used in formula. Help appreciated.

    Total risk appetite score

    [calculation total-riskapp id:risk “your-question1_flag + your-question2_flag + your-question3_flag + your-question4_flag+ your-question5_flag + your-question6_flag”]

    Total liquidity score

    [calculation total-liqneeds id:liquidity “your-question7_flag + your-question8_flag + your-question9_flag + your-question10_flag” ]

    <p>Your investment risk profile id <span id=”investment_profile”></span></p>

    <script language=”javascript” type=”text/javascript”>
    document.getElementById(“risk”).addEventListener(“change”, displayTextField);
    document.getElementById(“liquidity”).addEventListener(“change”, displayTextField);
    function displayTextField() {
    var r = document.getElementById(“risk”).value;
    var l = document.getElementById(“liquidity”).value;
    if (r > 60 && l < 50 ) {
    document.getElementById(“investment_profile”).innerHTML = ‘Growth’;
    } else if ((r >= 30 && l < 75 )||(r > 60 && l > 50 )) {
    document.getElementById(“investment_profile”).innerHTML = ‘Balanced’;
    } else {
    document.getElementById(“investment_profile”).innerHTML = ‘Income’;
    }
    }
    </script>

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author pbosakov

    (@pbosakov)

    Hi, the script itself looks right to me at a first glance. Where in the document body is it placed? Maybe it gets executed before the form fields are available in the DOM. You can try wrapping it in a document.ready event handler, like this:

    <script>jQuery(document).ready(function(){ /* Your code here */ });</script>

    Plugin Author pbosakov

    (@pbosakov)

    Thanks for your feedback. Since it’s been a month, I am marking this issue as resolved. Feel free to reply to this thread if the problem persists.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Using Calculated Field in Conditional Javascript to other output’ is closed to new replies.