<div id="header_div">
<select id="store_name_select" name="store_name_select" onchange="checkEnable(this,'store_name')">
<option value="" selected="selected" disabled="disabled"></option>
<option value="yes">Yes</option>
<option value="no">No</option>
</select>
<p>
<input disabled="" id="store_name" name="store_name" type="text">
</p>
<div>
<div>
<select id="store_address_select" name="store_address_select" onchange="checkEnable(this,'store_address')">
<option value="" selected="selected" disabled="disabled"></option>
<option value="yes">Yes</option>
<option value="no">No</option>
</select>
</div>
</div>
<p>
<input disabled="" id="store_address" name="store_address" type="text">
</p>
<select id="purchase_date_select" name="purchase_date_select" onchange="checkEnable(this,'purchase_date_month', 'purchase_date_day', 'purchase_date_year')">
<option value="" selected="selected" disabled="disabled"></option>
<option value="yes">Yes</option>
<option value="no">No</option>
</select>
<p>
<input disabled="" id="purchase_date_month" name="purchase_date_month" type="text"></span>
<input disabled="" id="purchase_date_day" name="purchase_date_day" type="text"></span>
<input disabled="" id="purchase_date_year" name="purchase_date_year" type="text">
</p>
</div>
Note 1: I do NOT own the site with this code so I can't change the page source code by editing it.
Note 2: I need a javascript (NOT JQuery)
Note 3: I'm accessing the website in question through Firefox or Waterfox web browser
I'm trying to make a greasemonkey (tampermonkey) script, which will do some things when browser access the web page. The above code is just a small piece of page source code. I made it more simple so you can only see whats important for this issue.
As you can see, page has multiple 'select' (tags). Current 'state' (or value) is 'not picked'. For all 'select' tags I can select from drop menu 'yes' or 'no'. Once I select 'yes', it will 'unlock' the input fields that were previously 'disabled'. Since most of the time the answer for 'select' is 'yes', I want to have a script which will automaticly select 'yes' for all 'selects' IDs, and 'unlock' (remove 'disable' state) for the 'inputs' that they are connected to. If I later need to switch from 'yes' to 'no' I'll do it manually.
I googled and searched before asking here, and although I did found some similar questions, NONE of the code worked, even if I tried to adopt it or change it to work for my case. I'm a newb so probably I missed something or coded it the wrong way, so please try not to criticize me too much. :)
For instance, I've tried this:
document.getElementsByTagName("select").selectedIndex = 1; //Option 'yes'
or
var test = document.querySelectorAll("#store_name_select, #store_address_select, #purchase_date_select");
for (var i = 0; i < test.options.length; i++) {
test.selectedIndex = 1;
}
^ that one also didn't work. At the top of that, (tampermonkey internal) script editor also warned me that 'i' is already defined. It's because I already used 'i' for other piece of code which does other things. Almost all the code that I can find ALL include 'i' letter. I wonder if I could use other letter for that line, eg.:
for (var b = 0; b < test.options.length; b++)
^ I did tried that line too but nothing has changed.
So, does anyone know how to get all 'select' IDs and force them to all select 'yes' (by value or by their 'index') and unlock input fields that are bound to them? Since this is a submit form, the owner needs to know that I selected 'yes' from drop menu. So the point is not only for the drop menu 'select' to unlock inputs, but to let the site owner 'know' that I actually did selected 'yes' before inputs removed their 'grayed out' cover.
THANK YOU in advance for your help!
If you need a 'test' page, here is the direct link to the page in question, so you can try your code and see if it really works: amzon microworkers page