kpcollier Posted April 7, 2022 Report Share Posted April 7, 2022 I have a submission form that is acting as a little calculator. It has one real field (Month) and a few virtual fields (Days, Crew Size, Hours). The Days virtual field is getting it's number value from cascading off of the Month dropdown field. I want the user to be able to change the number in the Days field, but if they enter in a number value that was greater than the original Cascading Value, then I want to change the border color and text color of the Days field to red. I've tried a few things, including this little bit I found on SO, with no luck. document.getElementsByClassName('cbFormTextField')[0].oninput = function () { var max = parseInt(this.max); if (parseInt(this.value) > max) { this.style.border = '2px solid red'; this.style.color = 'red'; } } Any help is appreciated. Quote Link to comment Share on other sites More sharing options...
kpcollier Posted April 7, 2022 Author Report Share Posted April 7, 2022 I was able to get it to work, but it's a little glitchy. document.getElementsByClassName('cbFormTextField')[0].addEventListener('keyup', applyColorHandler); function applyColorHandler() { let conditionField = document.getElementsByClassName('cbFormTextField')[1]; let virtualField = document.getElementsByClassName('cbFormTextField')[0]; if(parseInt(virtualField.value) > parseInt(conditionField.value)){ virtualField.style.border = '2px solid red'; virtualField.style.color = 'red'; } else { virtualField.style.border = '1px solid white'; virtualField.style.color = 'white'; } }; It seems like there's a state rule on the input field when in focus. The text turns red on keyup, but the border doesn't turn red until you focus out of the input field. Once you re-focus onto it, the border turns white again. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.