Jump to content

How to prevent a form to submit


Recommended Posts

  • 10 months later...

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!

Link to comment
Share on other sites

  • 3 weeks later...

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