jQuery and SharePoint

Copper Contributor

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 identifier like id, name, class of the combobox so i can use it in the jquery selector for that box. no luck. when i go into F12 in Edge while in the SP site and look at the Elements tab, all i see are a bunch of tr and td tags that surround the box with the current selection listed in a span tag. not what i need. can this be done??

note: i uploaded my jquery file into a content editor for the page that contains the combobox.

thanx for any assistance.

3 Replies
Are you using SharePoint Online or On-prem ?
If you are using Online, it's better that you make use of PowerApps for exactly this.
unfortunately it's on premises. anything else i can try?

Hi @palefire29,

the id of the label is the fieldname in a form on SharePoint classic mode

jquery.png


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-share... 
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