Unable to fill out the text field and submit automatically

好久不见. 提交于 2021-01-29 05:15:20

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!