Click here to Skip to main content
15,867,834 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi, I'm using this website and trying to autoselect in "Digita o seleziona la biblioteca" field:

Municipio X > Biblioteca Elsa Morante

I used this script in TamperMonkey, but doesn't react, where am I wrong? Thank you!

JavaScript
// ==UserScript==
// @name         New Userscript
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  try to take over the world!
// @author       You
// @match        https://www.bibliotechediroma.it/opac/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=google.it
// @grant        none
// ==/UserScript==

(function() {
    'use strict';
document.querySelector("button[class='syw-comboselect-trigger']").click();document.querySelector("li[data-group='GR_10'] a[title]").click();document.querySelector("li[data-cd='RMBO2'] a[class='select']").click();
})();


What I have tried:

document.querySelector("button[class='syw-comboselect-trigger']").click();document.querySelector("li[data-group='GR_10'] a[title]").click();document.querySelector("li[data-cd='RMBO2'] a[class='select']").click();
})();
Posted
Updated 6-Jan-23 0:28am

1 solution

Tampermonkey script that autoselects an item with a specific value in a dropdown menu:
JavaScript
// ==UserScript==
// @name Autoselect Dropdown Item
// @match https://example.com/*
// @grant none
// ==/UserScript==

(function() {
  'use strict';

  // Select the dropdown menu
  const dropdown = document.querySelector('#myDropdown');

  // Set the value of the dropdown menu to the desired item
  dropdown.value = 'item2';
})();

This script selects the element with the ID myDropdown and sets its value to item2. You can modify the script to select a different item by changing the value of the dropdown.value assignment.

To use this script, install Tampermonkey and create a new script. Paste the code into the script editor and save it. The script will run on pages that match the URL pattern specified in the @match directive (in this case, https://example.com/*).
 
Share this answer
 
Comments
Parvares 6-Jan-23 6:28am    
Thanks, I tried but I don't know which value to input instead of #myDropdown and item2.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900