首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >从javascript函数触发表单的操作属性

从javascript函数触发表单的操作属性
EN

Stack Overflow用户
提问于 2019-09-18 11:37:02
回答 1查看 470关注 0票数 0

我已经验证了我所有的表单域,之后,我想从提交函数触发表单操作。我试过很多方法,但似乎都不管用。感谢您的帮助。

代码语言:javascript
复制
(function() {
    //FORM VALIDATOR
    formValidator = {
        init: function() {
            this.cacheDom();
            this.bindEvents();
        },
        cacheDom: function() {
            //MAIN PARENT ELEMENT
            this.contactForm = document.getElementById("contactForm");
            //MAIN FORM ELEMENTS
            this.formBody = document.getElementById("formBody");
            this.inputContainer = document.getElementsByClassName("inputContainer");
            //USER INPUT ELEMENTS
            //INPUT FIELDS
            this.fields = {
                company: document.getElementById("company"),
                industry: document.getElementById("industry"),
                //rest of the fields

            };
            this.submitBtn = document.getElementById("submit");
        }
        submitForm: function() {
                //I want to trigger form action from this part but nothing seems to work
                document.getElementById("myForm").action = "https://google.com";

            }
        };
        //INITIATE FORM VALIDATOR
        formValidator.init();
}());

//HTML

代码语言:javascript
复制
    <div id="formBody" class="formBody">
        <form action="https://google.com" method="POST" name="becomessaform" id="becomessaform">
            <input type=hidden name="oid" value="****">
            <input type=hidden name="retURL" value="">
            <div class="row form-fields ">
                {/* all fields go here */}
            </div>
            <div class="row form-fields submit-button-cf"><input type="submit" id="submit" name="submit" class="button-submit"/></div>
        </form>
    </div>    
EN

回答 1

Stack Overflow用户

发布于 2019-09-18 11:46:01

您可以使用submit()在JS中提交表单。

在您的代码中,这将是:

代码语言:javascript
复制
submitForm: function() {
    document.getElementById("becomessaform").submit();
};
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/57984720

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档