简体   繁体   English

要么不能提交(); jQuery中的表单,或者无法检查输入字段是否已填写

[英]Either Can Not submit(); form in jQuery, or can not check if input fields are filled out

I am having trouble submitting the below form. 我无法提交以下表格。

For background, I'm trying to "submit" a form for a delivery, and I need to know a) their pickup address, b) their dropoff address, and c) their description. 对于背景,我试图“提交”送达表格,我需要知道a)他们的收货地址,b)他们的投递地址和c)他们的描述。 I created <p class="error"> fields if those <input> s are empty (as in "Please enter a description"). 如果这些<input>为空,则创建了<p class="error">字段(如“请输入描述”中所述)。

If I remove the 'return false;' 如果我删除“ return false”; the form submits no matter what, but if I keep the 'return false;' 该表单无论如何都提交,但是如果我保留“ return false”; the jQuery works (ie - error message appears) but now the form NEVER submits. jQuery可以正常工作(即-显示错误消息),但是现在从未提交过表单。 Thoughts? 有什么想法吗?

Here's my main.js 这是我的main.js

var main = function() {
  $('form').submit(function() {
    var pickup = $('#pickup').val();

    if(pickup === "") {
      $('.pickup-error').text("Please choose a pickup.");
    }



    var dropoff = $('#dropoff').val();

    if(dropoff === "") {
      $('.dropoff-error').text("Please choose a dropoff.");
    }

    var description = $('#description').val();

    if(description === "") {
      $('.description-error').text("Please tell us a little about what we're moving.");
    }

      return false;
  });
};

$(document).ready(main);
   var main = function () {
        $('form').submit(function () {

            var pickup = $('#pickup').val();
            if (pickup === "") {
                $('.pickup-error').text("Please choose a pickup.");
            }

            var dropoff = $('#dropoff').val();
            if (dropoff === "") {
                $('.dropoff-error').text("Please choose a dropoff.");
            }

            var description = $('#description').val();
            if (description === "") {
                $('.description-error').text("Please tell us a little about what we're moving.");
            }

            // did not pass validation
            if (pickup != "" || dropoff != "" || description != "") {
                return false;
            }

            // passed validation, submit
            return true;
        });
    };

    $(document).ready(main);

暂无
暂无

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

相关问题 检查输入字段是否填写在表单中 - Check if input fields are filled out in a form 使用Redux表单,如果未填写任何字段,如何禁用提交按钮? - Using Redux Form, how can I disable the submit button if no fields have been filled out? 检查所有输入字段是否已用jQuery填写 - Check all input fields have been filled out with jQuery 如何检查表单中所有必填字段的填写时间? - How can I check when all of the required fields of a form has been filled out? 即使未填写必填字段,我是否可以在超时时提交表单 - Can I submit form on timeout even if required fields are not filled 禁用表单提交按钮,直到填充所有输入/文本区域字段,而不使用 for 循环(无 jQuery) - Disable form submit button until all input/textarea fields are filled, without using for loop (no jQuery) 在.hta文件中保留表单字段(输入/选择/复选框)。 因此原始用户和/或其他用户可以打开并查看填写的信息 - Preserving form fields(input/select/checkbox) in an .hta file. So original user and/or another user can open and see the filled out information 如果未填写必填字段,如何防止提交表单上的函数调用? - How to prevent function call on submit form if required fields are not filled out? jQuery 检查是否填写了 4 个字段 - jQuery check if 4 fields are filled in 检查是否所有输入字段都填写完毕,然后调用函数js - Check whether all input fields are filled out, then call function js
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM