I have a Script Editor web part running on a 'NewForm.aspx' page that contains some javascript that pops up a confirmation box if a certain field contains a certain line of text when the user is creating a new item on the list.
If they click 'Ok' I want the form to submit (create the new item in the list), if they click 'Cancel' then return to the form submission page without submitting the form.
So far the pop-up shows up when they enter the 'test' into the 'Title field', and the 'Cancel' button works (by just returning them to their form without submitting), but clicking 'Ok' doesn't submit the form. It also just returns them to the form submission page as if they pressed 'Cancel.'
Here's my code:
<script type="text/javascript" src="/sites/gameops/SiteAssets/jquery-1.12.1.js"></script>
<script type="text/javascript">
var j = jQuery.noConflict();
function PreSaveAction() {
var txtTitle = j(":input[title='Title']").val();
if(txtTitle == 'test'){
confirm("Please enter a title"); //write popup code here
return false;
}
else{
return true;
}
}
</script>