问题
What I am trying to accomplish is to populate the text box for "Reason for Access" with the word "TEST" using Tampermonkey. (I'm very new to using Tampermonkey & UserScript so please be patient with me.)
I am having an issue where the "Reason for Access" is still blank and isn't submitting automatically.
Would you be able to provide assistance? Let me know if you need anything.
This is my userscript:
function ClickURL2() {
var FillF2 = document.getElementsByName("reason");
FillF2[0].value = "TEST";
var FormSub = document.getElementsByName("crm-info crm-dialogue");
FormSub[0].submit();
}
This is the source of the webpage:
<form name="profileForm">
<fieldset>
<div class="labelGroup">
<div class="crm-legend">
<span class="required" title="Required">*</span> = Required<br>
<span class="audited" title="Available to Gatekeeper Users">†</span>
= Available to Gatekeeper Users
</div>
<div class="crm-form-container">
<div class="crm-profilefield">
<div class="field-label">
<span class="audited" title="Available to Gatekeeper Users">†</span>
<span class="required" title="Required">*</span>
Reason for Access</div><div class="field-input">
<input class="" type="text" name="reason" required="required" title="" style="">
</div>
<div class="ui-helper-clearfix"></div></div><input type="submit" class="hidden" style=""></div>
</div>
</fieldset>
</form>
回答1:
When submitting the form with javascript, you should be using submit() on the form element. I tested the other code and it seems to add the value to the textbox just fine.
var FormSub = document.getElementsByName("profileForm");
FormSub[0].submit();
来源:https://stackoverflow.com/questions/59958600/unable-to-fill-out-the-text-field-and-submit-automatically