Thank you for taking the time to read my question.
I have a simple script in a SharePoint NewForm.aspx which initially hides a field on the form and then displays it if Yes is chosen in response to a question field. Here's the code:
<script src="https://code.jquery.com/jquery-1.7.2.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function() {
//Hide fields initially
$('nobr:contains("abc")').closest('tr').hide();
//Show field if Yes is chosen from the drop down list
$("select[title$='My question here?']").change(function() {
if($(this).val() == "Yes" ) {
$('nobr:contains("abc")').closest('tr').show();
} else {
$('nobr:contains("abc")').closest('tr').hide();
}
});
});
</script>
The problem with it is that some of the fields in the form are required fields, and if the user submits the form without completing the required fields, then:
- The field that needs to be completed is highlighted, which I want
- The script above is rerun and the form field is hidden again, which I don't want
How do I prevent the hide script being rerun?
Hoping someone can help.