简体   繁体   English

关于用JS提交表格

[英]Regarding the submission of a form with JS

I am currently attempting to fix a hyperlink on a page that is meant to act as a form submit button. 我目前正在尝试修复旨在用作表单提交按钮的页面上的超链接。

The button is supposed to do two things: 该按钮应该做两件事:

  1. Check if a validation function, called empty(); 检查是否有一个名为empty()的验证函数; , returns true ,返回true

  2. If so, submit the form 如果是这样,请提交表格

The button code is: 按钮代码为:

<a role="button" class="button_primary" id="WC_AccountDisplay_links_2" onclick="submitLogonForm();">
 <div class="left_border"></div>
 <div class="button_text">Sign In</div>
 <div class="right_border"></div>
</a>

The onclick code is: onclick代码为:

<script>

function submitLogonForm() {

 return empty();

  if(empty()) {

    document.Logon.action="security.php";
    document.Logon.submit();

  }

}

</script>

And the form code is: 表单代码为:

<form method="post" name="Logon" action="security.php" id="Logon">

The empty() check runs fine, but the form does not submit, and I can't figure out what I'm missing. empty()检查运行正常,但表单未提交,我无法弄清缺少的内容。

Any help would be greatly appreciated. 任何帮助将不胜感激。

function submitLogonForm() {
  if(notempty()) {

    document.forms[0].submit();

  }
}
function notempty() {
   // do validations here 
   //if any field is empty - return false 
   //else 
   return true;
}


<form action="security.php">
<a role="button" class="button_primary" id="WC_AccountDisplay_links_2" onclick="submitLogonForm();">
 submit
</a>
</form>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM