Copy link to clipboard
Copied
Hi all,
I am creating a fillable form to collect data, however two of the selectable fields require additional information.
I have created the page with the following fields:
The drop down includes 'Companies House' and 'Office for Students'. When either of these are selected, the wording on the left of the text box changes to ask for the required number. All other selections should be N/A.
The issue I have is trying to make the text box be uneditable and not required when N/A is showing and editable/required when 'Companies House' or Office for Students (OFS)' is selected.
The code I am using in the dropdown is:
var number = this.getField("Company/OFS Number");
if(event.value == "Companies House")
number.value = "";
else if(event.value == "Office for Students (OFS)")
number.value = "";
else number.value = "N/A";
If I add 'number.readonly = true;' to the end, it locks the form and adding 'number.readonly = false;' gives an error.
Any assistance in resolving this would be most welcome.
Copy link to clipboard
Copied
Hi Thom,
Thank you for your reply.
I am sorry if my post was not fully complete and I used the incorect naming convention. I will definitely take your comments onboard for any future posts I make and also for my general learning of the conventions to use.
I added the code and this worked fine for 'Companies House' but was not working for the 'OFS' field. This made me read the code in order to understand it better. I then found that I need to change cOFSNum .value to event.value
else if(cOFSNum .value == "Office for Students (OFS)")
Everything is now working correctly and as intended.
Thank you so much fo your assistance with this.
Copy link to clipboard
Copied
So first, "number" is not a good name for a variable, since it's also the name of a type in JS.
Try this code:
var cOFSNum = this.getField("Company/OFS Number");
cOFSNum.readonly = false;
if(event.value == "Companies House")
cOFSNum.value = "";
else if(event.value == "Office for Students (OFS)")
cOFSNum.value = "";
else{
cOFSNum.value = "N/A";
cOFSNum.readonly = true;
}
Please be specific in your comments. If there is an error, don't just say there is an error. Tell us what error, where and how is it reported? When does it happen?
A phrase like "locks the form" doesn't mean anything to us. Are all the form fields on the form uneditable? Or just one form field. Be specific.
Copy link to clipboard
Copied
Hi Thom,
Thank you for your reply.
I am sorry if my post was not fully complete and I used the incorect naming convention. I will definitely take your comments onboard for any future posts I make and also for my general learning of the conventions to use.
I added the code and this worked fine for 'Companies House' but was not working for the 'OFS' field. This made me read the code in order to understand it better. I then found that I need to change cOFSNum .value to event.value
else if(cOFSNum .value == "Office for Students (OFS)")
Everything is now working correctly and as intended.
Thank you so much fo your assistance with this.
Copy link to clipboard
Copied
Excellent Catch!! I fixed it in the post.