I'm using a simple PreSaveAction() on my custom Edit Form. This is SharePoint 2013 on-premise. The goal is to validate a drop down menu against a text field. ie. If the Status drop down is set to "Unfilled" then ensure that the "Unfilled reason" text field has some text.
I added a Script Editor Webpart to the page and added the following code:
<script src="https://shoreline/sites/sitename/SiteAssets/jquery-1.11.3.min.js"></script>
<script language="javascript" type="text/javascript">
function PreSaveAction()
{
alert("test");
var val1 = document.getElementById('ctl00_ctl40_g_66098ca8_a834_4817_9ed3_147b323e8424_ff91_ctl00_DropDownChoice'); //get value from dropdown - Status
alert("val1 Status = " + val1.value);
var val2 = document.getElementById('ctl00_ctl40_g_66098ca8_a834_4817_9ed3_147b323e8424_ff101_ctl00_ctl00_TextField'); // get text field - Unfilled Reason
alert("val2 unfilled reason = " + val2.value);
if (val1.value = "Unfilled" && val2.value=="")
{
alert("Please double check your information.");
return false;
} else {
return true;
}
}
</script>
The alerts are working and showing the correct values, however the Status field which is defaulted to "Pending" (or could be anything previously selected in the drop down) automatically clears to blank - but then saves using the default "Pending" even when it changed to "Unfilled".
Any idea why this is happening or how to prevent it?