0

I have a simple list with a single line of text column. I have a JS function that reads data from other list an set default value for this column in the new form. I simply use.

$(“select[Title=’Fieldname’]”).val(‘Value’);

All works well, if I change my column type and set "Require that this column contains information" to true, the code no longer works. Anyone knows why and how I can get around this issue?

0

When you make the the field required it changes the title attribute of field element . So the selector you are using does not return any element.

You can see the title of the field by inspecting respective textbox/select element on new form in developer tool.

Try using below selectors:

Using Title property:

$("select[title='Fieldname Required Field']").val("Value");

Here Fieldname is display name of field.

Using Id property:

Using Id for element selector is bit tricky in SharePoint as it appends unnecessary string in id attribute by default.

$("select[id^='Fieldname']").val("Value");

^ denotes that id starts with your Fieldname(Internal name of field).

  • That is amazing, thank you so much. I used $(“select[id=’Fieldid']”).val(‘Value’); so I dont have to worry about updating the title – sam Sahelly Nov 1 '18 at 5:09
  • Yes, but using Id for element selector is bit tricky in SharePoint. see updated answer. – Ganesh Sanap Nov 1 '18 at 6:26
  • @samSahelly If this answer helped you in any way then please accept an answer so that other users can get help from accepeted answer easily. – Ganesh Sanap Nov 1 '18 at 9:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.