Hi,
I am working on a form and cannot seem to get a line of javascript working. I admit this is my first go at Java and I have done a bit of reading, but don't have a ton of time right now to spend learning it completely (in the future for sure).
I am trying to clear fields based on the user selecting 'No' from a choice field (radio buttons). I have the following code
NWF$(document).ready(function() { var jsvarChoiceChange = NWF$("#" + varYesNo); jsvarChoiceChange.change(function() { NWF$("#" + varCheckbox1).find("input:checkbox[value='Test1']").attr("checked",false); NWF$("#" + varCheckbox1).find("input:checkbox[value='Test2']").attr("checked",false); NWF$("#" + varCheckbox1).find("input:checkbox[value='Test3']").attr("checked",false); NWFS('#' + varSingleLineTextClear).val(''); var jsvarClearPeoplePicker = new NF.PeoplePickerApi('#' + varPerson); jsvarClearPeoplePicker.clear(); var jsvarClearRichText = NWF$('#'+ varMultiLine).closest('tr').find('div[id$="_inplacerte"]'); jsvarClearRichText.html(''); }); });
This will clear the values from the fields but it willl clear the values even if you pick yes, which I don't want. The 'varYesNo' is a SharePoint choice column with Yes and No as options, set to a radio button. I am doing this because the actual form was setup that way and changing it now would be difficult.
I tried the following, but didn't work.
NWF$(document).ready(function() { NWF$('#' + varMainYesNo).change(function(){ if(NWF$('#' + varMainYesNo).val('No')){ NWF$("#" + varCheckbox1).find("input:checkbox[value='Test1']").attr("checked",false); NWF$("#" + varCheckbox1).find("input:checkbox[value='Test2']").attr("checked",false); NWF$("#" + varCheckbox1).find("input:checkbox[value='Test3']").attr("checked",false); NWFS('#' + varSingleLineTextClear).val(''); var jsvarClearPeoplePicker = new NF.PeoplePickerApi('#' + varPerson); jsvarClearPeoplePicker.clear(); var jsvarClearRichText = NWF$('#'+ varMultiLine).closest('tr').find('div[id$="_inplacerte"]'); jsvarClearRichText.html(''); } }); });
I have searched the web, and here and cannot find or make sense. Any assistance would be greatful.
Thanks,
Solved! Go to Solution.
Hi,
your approach with the if is correct, but you are unintentionally setting a value instead of reading it.
You can read the selected option using this:
NWF$("#" + yourChoiceControlVar + " input:checked").val()
So you could change your condition in you if from
NWF$('#' + varMainYesNo).val('No')
to
NWF$("#" + yourChoiceControlVar + " input:checked").val() === "No"
and it should work only when "No" is selected.
Hi Tarf,
Thank you that worked! Appreciate the response and help!