Jump to content
Sign in to follow this  
telly

How to prevent a form to submit

Recommended Posts

Hi Telly,
 You can try this: 

<script type="text/javascript">
document.addEventListener('BeforeFormSubmit', function(event) {
  if (condtion) {
    //result if condition is met
  } else {
   event.preventDefault()
  }
});
</script>

Also, check this helpful link: 
https://howto.caspio.com/datapages/ajax-loading/
 

Share this post


Link to post
Share on other sites

Hi @telly,

You can use this code to prevent a submission form if a certain condition is not met.

<script type="text/javascript">
document.addEventListener('BeforeFormSubmit', function () {

event.preventDefault();

var a = document.getElementById("InsertRecordFIELDNAME").value;

if (a > 100) {
alert('Please enter number less than 100.');
}

else {
document.forms["caspioform"].submit();
}

});
</script>

 

Cheers!

Share this post


Link to post
Share on other sites

Slight modification to get this to work - it appears that the ID now has a number appended to it (e.g., InsertRecordFIELDNAME_7647422799) . You can use the document.getElementsByName to find the first name in the array.

<script type="text/javascript">
document.addEventListener('BeforeFormSubmit', function () {

event.preventDefault();

var a = document.getElementsByName("InsertRecordFIELDNAME");

if (a[0].value > 100) {
alert('Please enter number less than 100.');
}

else {
document.forms["caspioform"].submit();
}

});
</script>

Share this post


Link to post
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...
Sign in to follow this  

×
×
  • Create New...