简体   繁体   English

我的表单不适用于我的 Javascript 验证

[英]My Form isn't working with my Javascript validation

I don't know if the problem is with my form or my javascript but the validation isn't working and I'm not getting any errors in the console.我不知道问题出在我的表单还是 javascript 上,但验证不起作用,我在控制台中没有收到任何错误。 Can anyone check and see the form is working or the problem is with the javascript任何人都可以检查并查看表格是否有效或问题出在 javascript

 const formSection = document.getElementById('davididhere'); const mailInput = document.getElementById('email'); const messageError = document.getElementById('error-messages'); formSection.addEventListener('submit', (e) => { if (mailInput.value === mailInput.value.toLowerCase()) { messageError.textContent = ''; } else { e.preventDefault(); messageError.textContent = '*email must be in lower case <br> * form not sent'; } })
 <section id="contactpage" class="form-section"> <div class="form-container"> <form action="https://formspree.io/f/myyvzkag" method="post" id="davididhere"> <ul class="form-info"> <li> <input type="text" maxlength="30" name="user_name" class="name-text-box" id="full-name" placeholder="Full Name" required="" /> </li> <li> <input type="email" name="user_email" class="name-last-text-box" id="email" placeholder="Email Address" required="" /> </li> <li> <textarea id="text-box" name="message" maxlength="500" class="enter-form" cols="30" rows="10" placeholder="Enter text here" required=""></textarea> </li> </ul> <input type="submit" value="Get in touch" class="send-btn" /> <small id="error-messages"></small> </form>

Code snipped is working here.代码剪切在这里工作。 Now the question is do you expect some kind of an error in the console since you stated that you are not receiving anything there.现在的问题是您是否期望控制台中出现某种错误,因为您声明您没有在那里收到任何东西。 You can throw an error in addition to already defined textContent .除了已经定义的textContent之外,您还可以throw错误。

const formSection = document.getElementById('davididhere');
const mailInput = document.getElementById('email');
const messageError = document.getElementById('error-messages');

formSection.addEventListener('submit', (e) => {
  if (mailInput.value === mailInput.value.toLowerCase()) {
    messageError.textContent = '';
  } else {
    e.preventDefault();
    messageError.textContent = '*email must be in lower case <br> * form not sent';
    throw new Error('Email must be in lower case!');
  }
})

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

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