简体   繁体   English

填写所有字段后如何激活提交按钮

[英]How to Activate Submit button once all fields are filled

I have the following code displaying input fields in a form. 我有以下代码以表格形式显示输入字段。 I want to have the submit button active only once all fields are filled. 我只想在所有字段都填满后才激活提交按钮。 I cant seem to figure out where I've gone wrong. 我似乎无法弄清楚哪里出了问题。 I have omitted some text inputs here for space. 我在这里省略了一些空格的文本输入。

Form: 形成:

    <?php
    if(@$_GET['q']==4 && !(@$_GET['step']) ) {
    echo ' 
    <div class="row">
    <span class="title1" style="margin-left:40%;font-size:30px;"><b>Enter Quiz Details</b></span><br /><br />
     <div class="col-md-3"></div><div class="col-md-6">   <form class="form-horizontal title1" name="form" action="update.php?q=addquiz"  method="POST">
    <fieldset>


    <!-- Text input-->
    <div class="form-group">
      <div class="col-md-12">
      <label for="name">Enter Title</label>
      <input id="name" name="name" class="form-control input-md" type="text">

      </div>
    </div>
    <div class="form-group">
      <label class="col-md-12 control-label" for=""></label>
      <div class="col-md-12"> 
        <input  type="submit" style="margin-left:45%" class="btn btn-primary" value="Submit" class="btn btn-primary" id="submit" disabled="disabled"/>
      </div>
    </div>

    </fieldset>
    </form>
    </div>';

    }
?>

<script>
(function() {
    $('form input').keyup(function() {

        var empty = false;
        $('form > input').each(function() {
            if ($(this).val() == '') {
                empty = true;
            }
        });

        if (empty) {
            $('#submit').attr('disabled', 'disabled'); //Leave as disabled if any of the  fields are empty
        } else {
            $('#submit').removeAttr('disabled');//Remove the disabled attribute once all fields are filled
        }
    });
});
</script>

The code is exactly as it appears here. 代码与此处显示的完全相同。 If I've missed something, kindly point me in a direction. 如果我错过了什么,请给我一个方向。 Thank you. 谢谢。

You are using the attribute as disabled="disabled" buts its an attribute having no value you should use it like this <input type="submit" style="margin-left:45%" class="btn btn-primary" value="Submit" class="btn btn-primary" id="submit" disabled/> 您使用的属性为Disabled =“ disabled”,但其属性没有值,则应使用此<input type="submit" style="margin-left:45%" class="btn btn-primary" value="Submit" class="btn btn-primary" id="submit" disabled/>

Here I have created a working JSFiddle for you check it and do correction https://jsfiddle.net/g1cra5f8/ 在这里,我创建了一个工作的JSFiddle,供您检查并进行更正https://jsfiddle.net/g1cra5f8/

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

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