Announcement

Collapse
No announcement yet.

JavaScript problem calculating field result

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • JavaScript problem calculating field result

    I'm having difficulty getting a calculation to produce a result.
    I have four text boxes

    Max
    Change
    Modify
    Current


    Max is user input
    Change is user input
    Modify is user input
    Current is calculated

    I have this code in the "Calculate/Custom calculation script" box of the "Current" Text Field Properties:

    if (this.getField ("Max").value===""){
    event.value=""
    }
    else{
    event.value=(this.getField("Current")+(this.getFie ld("Change")+(this.getField("Modify")).value))
    }

    Expected output of Current:
    a value which can be negative, but may not exceed the sum of Max + Modify

    What I do get is blank. Nothing.

    I could use some help as I have no experience with JavaScript and have done no programming at all in 10 years.

    Thank you, in advance, for your time and attention.

  • #2
    Hi Static,

    Could you please confirm how would you like to calculate the field Current? To sum up?

    Comment


    • #3
      It is because the values you extract from your input fields are strings. When you add two strings, they are usually concatenated. Try looking at the javascript method parseIntas Evan suggests in the comments or look at parseFloatif you want to allow floats https://krogerfeedback.me/www-kroger...oger-feedback/.

      Comment

      Working...
      X