简体   繁体   中英

Greasemonkey Script to change drop down option if either of 2 options are selected

So, I have a form that accepts values and on submit appends the values to another form in multiple tabs.

I'm trying to select the second option of a dropdown if the user chose IT or ES.

Here is my greasemonkey:

var taxcty = document.getElementById("CountryCode");
if (taxcty.options[taxcty.selectedIndex].value == 'IT' || 'ES'){

  (document.querySelector && document.querySelector('select[name="currentState"]') || []).value = 'Unverified';
}

So in theory, if the user selects IT or ES in the "CountryCode" field, I want the currentState field to change to "Unverified".

It's partially working right now but it is also changing all other country codes to Unverified lol. So if I chose "GB" it actually changes to Unverified but I only want it to do that for IT or ES.

if (taxcty.options[taxcty.selectedIndex].value == 'IT' || taxcty.options[taxcty.selectedIndex].value == 'ES'){

You need to have both sides of the comparison for all values. 'ES' as a standalone operand will always be true as it is not null, empty or false.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM