Forum Discussion
palefire29
Jan 24, 2023Copper Contributor
jQuery and SharePoint
this is kind of a weird one. what i'm looking to do is change the state of multiple items in a dropdown list depending on the current selection but i'm having trouble getting a hold of some identifie...
SvenSieverding
Jan 26, 2023Bronze Contributor
Hi palefire29,
the id of the label is the fieldname in a form on SharePoint classic mode
You can use JQuery like this to select the option "Choice1" of a choice column named "Dropdown":
$("#Dropdown").parent().parent().find("td.ms-formbody>span>select>option:contains('Choice1')").prop('selected', true)
But it might be better if you take a look at JSLINK.
https://learn.microsoft.com/en-us/archive/msdn-magazine/2014/june/sharepoint-using-jslink-with-sharepoint-2013#working-with-jslink
It is a more "standard" way to change a classic SharePoint form using javascript.
(You can even use React with JSLINK, see an example here: https://github.com/365knoten/jslink-react-sample)
Best Regards,
Sven