Jump to content

what am I doing wrong here?


Recommended Posts

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>

Link to comment
Share on other sites

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>

 

Link to comment
Share on other sites

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.   

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...