How to hide/show <div> after NewForm.aspx saves data in Sharepoint 2016
-
19-02-2021 - |
Question
After a user clicks "Save" on NewForm.aspx, I'd like to show/hide a div tag with a message instead of returning the user to the list showing all the responses. My tags are below, but I just can't figure out how/where to take over the built in "Save" button that is displayed in NewForm.aspx to then dynamically change the style of the div tag.
<div class="success" style="display: none;">
<div class="alert alert-success" role="alert"><i class="fas fa-thumbs-up"></i>Request Submitted!</div>
</div>
<div class="failure" style="display: none;" >
<div class="alert alert-danger" role="alert"><i class="fas fa-exclamation-triangle"></i>Submit Failed!</div>
</div>
Solution
The style display property is used to hide and show the content of HTML DOM by accessing the DOM element using JavaScript/jQuery.
To hide an element, set the style display property to “none”.
document.getElementById("element").style.display = "none";
To show an element, set the style display property to “block”.
document.getElementById("element").style.display = "block";
Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange