0

I want to always maintain how to select the second option for its drop downs. The point here is that the value is random:

MyBrowser.document.getElementById("multipleCat_1").Value = "RANDOMVALUE"

How do I select the second option in a drop down menu?

HTML:

<select id="multipleCat_1">
    <option value="-1">Select</option>
    <option value="RANDOMVALUE">Second Option"</option>
</select>
Jonathan Brizio
  • 1,087
  • 1
  • 14
  • 28
nubteens
  • 5,462
  • 4
  • 20
  • 31
  • 1
    Possible duplicate of [How can I set the default value for an HTML – buræquete Apr 13 '17 at 16:04
  • @bureaquete, I do not have access to the HTML code as I am only trying to access the website as mentioned. – nubteens Apr 13 '17 at 16:06

2 Answers2

1

You can use selectedIndex as below:

document.querySelectorAll('#multipleCat_1 > option')[1].value = 'Got you!';

document.getElementById('multipleCat_1').selectedIndex = 1 

console.log(document.getElementById('multipleCat_1').value)
<select id="multipleCat_1">
    <option value="-1">Select</option>
    <option value="RANDOMVALUE">Second Option"</option>
</select>
Tareq
  • 5,283
  • 2
  • 15
  • 18
0
<select id="multipleCat_1">
    <option value="A">AAA</option>
    <option value="B">BBB</option>
    <option value="C">CCC</option>
</select>

var options = document.querySelectorAll('#multipleCat_1 > option');
document.getElementById('multipleCat_1').value = options[1].value;
Vaibhav Nigam
  • 1,334
  • 12
  • 21