0

I'm quite new to coding and trying to come up with a way to pre-populate a dropdown field with a list value (it always needs to be the same default one). I have extracted the html code from the webpage, need to get option ID 1:

<select isrequired="1" validationcaption="Action type" name="td_type" style="width: 264px;"> 
    <option value="">(Select)</option><option value="29682776">Email (Calendar &amp; To-Do List)</option>
    <option value="2">Meeting (Calendar &amp; To-Do List)</option>
    <option value="1">Phone Call (Calendar &amp; To-Do List)</option>
</select>

The thing that puzzles me is how to make the script choose the ID from this dropdown. Is this done using the validationcaption or name value?

I could do with some pointers or part of the code or some instructions!

1 Answers1

0

Welcome to SO.

If I got you right, what you want to do can be done in a single line after your UserScript header section

document.querySelector("select[name='td_type']").value = 1;

Assuming it's the only select by that name on your website. To select an option you pass its value to the select itself.

Some more info about select and how to use them can be found here and here

Pinkie Pie
  • 688
  • 7
  • 15