sgriesbach Posted November 14, 2022 Report Share Posted November 14, 2022 hi Community, I could sure use a little help here. What am I doing wrong in this simple script to validate some data on a report form with details? Thank you so much, I am not a JS person! <script> function chk_main(){ var maint = document.getElementById('EditRecordSomeTextParm').value; var mhb = document.getElementById('EditRecordSomeIntParm').value; if ( maint == 'SQUARE' ) { if (mhb <= 0) { document.getElementById('EditRecordSomeTextParm').value = 'STD'; } } } document.getElementById('caspioform').onsubmit=chk_main; </script> Quote Link to comment Share on other sites More sharing options...
Volomeister Posted November 15, 2022 Report Share Posted November 15, 2022 Hi @sgriesbach In Caspio, there is "BeforeFormSubmit" event that occurs when a user is attempting to submit a form. You can read more here: https://howto.caspio.com/datapages/ajax-loading/ So we need to add event listener to the document to listen for "BeforeFormSubmit" event and then run the function you need. Try this code instead: <script> if(typeof validateInput == 'undefined') { const validateInput = () => { const inputText = document.getElementById('EditRecordSomeTextParm') const inputInt = document.getElementById('EditRecordSomeIntParm') if (inputText.value == 'SQUARE') { if(inputInt.value<=0) { inputText.value = 'STD'}} document.removeEventListener('BeforeFormSubmit', validateInput ) } document.addEventListener('BeforeFormSubmit', validateInput ) } </script> Ilyrian 1 Quote Link to comment Share on other sites More sharing options...
sgriesbach Posted November 15, 2022 Author Report Share Posted November 15, 2022 Hi Volomeister, Holy cow I would never in a million years have figured that out. Thank you so much! I just tested and it works perfectly. My datapage works now, so I'm leaving it alone! But just out of curiosity, would I be better off checking the "Disable AJAX Loading" on these datapages? The table(s) are relatively small, as are my datapages so I wouldn't expect this would be a big time sink in terms of the form load times. 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.