Jump to content

Change Value of Field Based On Calculated Value


Recommended Posts

I have a calculated value field (SQFT) that calculates the square footage from user-inputted Width and Height values. I have another text field named SQFT_Override. I am trying to create a script that, if SQFT is less than 3 and not blank, then fill the SQFT_Override value with 3. I can't quite get it to work. 

First I was trying just a simple if statement with JS. I was able to change the value of SQFT_Override, but I couldn't get it to work with the second condition - SQFT can't be blank. I tried !== null and !== '' and couldn't get it to work. 

I also had a problem with the script only running once. If the width or height was changed afterwards, thus changing the SQFT value, SQFT_Override would still have '3' as its value. So, I tried wrapping it in a change event, but still can't get it to work. Below is my attempt. Any help would be appreciated.

document.addEventListener('DataPageReady', function (event) {
  
     document.querySelector('[id*="SQFT"]').addEventListener("change", sqftMinimum); 
   
      function sqftMinimum(event) {
   
          let checker = event.target.value;

          var putter = document.querySelector('[id*=SQFT_Override]');

          if (checker.innerText < 3 && checker.innerText !== null) {
          	putter.value = 3;
          } else { putter.value = '' }  
     
     }        
});

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...