I am working on a team site inside sharepoint 2013. and inside my custom list i added this javascript to prevent closing an item unless the user enter a multi-line text field named "Analysis":-
<script language="javascript" type="text/javascript">
function PreSaveItem(){
var result = true;
var status=$("select[id*='UserStatus_'] option:selected").text();
if( status == "Closed")
{
var analysis = $('input[id^="Analysis_"]').val().trim();
alert(analysis);
if( analysis == "<p></p>"){
alert("Please Enter Analysis before closing the item");
result = false;
}
}
return result;
}
</script>
But I am not sure why the script is not getting the updated value for the input[id^="Analysis_"]
as we update the list item fields?.
For example let say i set the status = "Closed" + left the "Analysis" input empty, and i click on "Save" >> so i will get an error message correctly. but if i enter values inside the "Analysis" input and i click on "Save" again, i will still get the same error and i popup alert(analysis);
will not take the updated text which i entered. is this a caching problem inside the PreSaveItem()
function?