我已经验证了我所有的表单域,之后,我想从提交函数触发表单操作。我试过很多方法,但似乎都不管用。感谢您的帮助。
(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
<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> 发布于 2019-09-18 11:46:01
您可以使用submit()在JS中提交表单。
在您的代码中,这将是:
submitForm: function() {
document.getElementById("becomessaform").submit();
};https://stackoverflow.com/questions/57984720
复制相似问题