Suppose i have a textbox and a select box with like this.
<input type="text" id="txt"><br/><br/>
<select id="sel"></select>
<option value="0"> Select Value </option>
<option value="1"> Option 1</option>
<option value="2"> Option 2 </option>
</select>
when i click on that textbox and write some thing It will generate new option value to the select box by some others method.( Means I am using TamperMonkey for some website and they use some method to populate the option value and i want to automatically select the newly generated option through tamparmoneky ). This is the newly generated option value.
<select id="sel"></select>
<option value="new0"> Select Value </option>
<option value="new1"> New Option 1</option>
<option value="new2"> New Option 2 </option>
<option value="new3"> New Option 3 </option>
</select>
My code is
$(document).ready(function() {
$('#txt').val("somevalue");
//Trigger onchange event
$('#txt').trigger('change');
// now how to know when option has changed
$('#sel').change(function() {
alert( 'Handler for .change() called.');
$('#sel').val("new3");
});
});
My goal is when The website open the TamperMonkey script automatically enter some value to textbox and trigger a change event. The original site has some function on change event. By which they populate new option value to the select box. Now the problem is i dont understand when they load the option value. How to know when the new option value loaded and then select the value from my Tamper Monkey script?