JavaScript表单错误?

JavaScript表单错误?,javascript,php,html,forms,Javascript,Php,Html,Forms,我有以下表格。JavaScript之所以有效,是因为我将其用于其他表单。基本上禁用“添加地址”继续按钮,直到完成所有字段。但是我添加了一个地址功能,用户只输入他们的门牌号和街道,然后其他两个字段town和postcode会自动填充。这个功能的JavaScript不会显示为不需要。因此,由于这两个字段是自动填充的,并且用户没有输入它们,所以原始JavaScript不起作用,“添加地址”继续按钮保持禁用状态。有什么想法吗 编辑: 我已经设法解决了这个问题。我重新安排了表格,将“国家名单、门牌号、城镇

我有以下表格。JavaScript之所以有效,是因为我将其用于其他表单。基本上禁用“添加地址”继续按钮,直到完成所有字段。但是我添加了一个地址功能,用户只输入他们的门牌号和街道,然后其他两个字段town和postcode会自动填充。这个功能的JavaScript不会显示为不需要。因此,由于这两个字段是自动填充的,并且用户没有输入它们,所以原始JavaScript不起作用,“添加地址”继续按钮保持禁用状态。有什么想法吗

编辑:

我已经设法解决了这个问题。我重新安排了表格,将“国家名单、门牌号、城镇和邮政编码”放在表格的开头而不是结尾。它现在起作用了。但不知道为什么会有不同

     <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Payment Gateway</title>
    <link rel="stylesheet" type="text/css" href="ue1.css">
    <link rel="stylesheet" type="text/css" href="bootstrap.css">
    <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js"></script>
    <script src="https://maps.googleapis.com/maps/api/js?v=3.exp&libraries=places"></script>
    <script type="text/javascript" language="javascript">
        $(document).ready(function(){
        $('#firstname, #surname, #addresslist, #autocomplete').bind('keyup', function() {
            if(allFilled()) $('#continue').removeAttr('disabled');
        });

        function allFilled() {
        var filled = true;
        $('body input').each(function() {
        if($(this).val() == '') filled = false;
        });
        return filled;
        }
        });
    </script>

    <script>
        var placeSearch, autocomplete;
        var componentForm = {
        locality: 'long_name',
        postal_code: 'short_name'
         }; 
    </script>

   <form action="addaddresspage3.html" method="post" id="form" class="form">
        <div id="form1">

        <div class="row form-row form-bg">
            <div class="container">
                <div class="col-md-12 form-wrapper">
                    <form role="form">
                        <div class="form-content">
                            <legend class="hd-default">Billing Address</legend>


                            <div class="row">
                                <div class="form-group col-md-4 col-sm-6">
                                    <label for="first-name">First Name(s)*:</label> 
                                    <input type="text" id="firstname" class="form-control" placeholder="First Name(s)" required="">
                                </div>
                            </div>

                            <div class="row">
                                <div class="form-group col-md-4 col-sm-6">
                                    <label for="password">Surname*:</label>
                                    <input type="text" id="surname" class="form-control" placeholder="Surname" required="">
                                </div>
                            </div>

                            <div class="col-md-12">
                                <div class="row">
                                    <div class="form-group col-md-3 col-sm-3">
                                        <label>Country of Home Address</label>
                                        <select name="title" id="addresslist" class="form-control">
                                            <option value="1">Select Address</option>
                                            <option value="1">United Kingdom</option>
                                            <option value="2">Saudi Arabia</option>
                                            <option value="3">Iran</option>
                                            <option value="4">Nigeria</option>
                                        </select>

                                    </div>
                                </div>
                                <div class="row">
                                    <div class="form-group col-md-4 col-sm-6">


                                    <label for="street_<cfoutput>#Add#</cfoutput>">House number and street:</label>
                                        <input type="text" name="street_#Add#" validateat="onSubmit" validate="maxlength" required="yes" id="autocomplete"  size="54" maxlength="120" message="Please enter owner #Peoplecount#'s mailing address." onFocus="geolocate()" placeholder="Please enter your house number and street">


                                        <p>

                                            <label for="city_<cfoutput>#Add#</cfoutput>">Town:</label>
                                            <input type="text" name="city_#Add#" validateat="onSubmit" validate="maxlength" required="yes" id="locality" size="30"  maxlength="50" message="Please enter owner #Peoplecount#'s mailing city." value="">       

                                        </p>

                                        <label for="street_<cfoutput>#Add#</cfoutput>">Postcode:</label>
                                         <input type="text" name="postal_#Add#" required="yes" id="postal_code" size="8" maxlength="12"  message="Please enter owner #Peoplecount#'s mailing zip code." value="">
                                    </div>
                            </div>
                    </div>
</div>

</div>
   <input type="submit" id="continue" disabled="disabled" value="Add Address"/>
</div>

设置输入字段的值后,激发该字段的keyup事件

function setValues(){
    var my_field = $('#myfield');
    my_field.val('Alice');
    my_field.trigger('keyup');
}
就你而言,我认为这样做就足够了:

$('#firstname, #surname, #addresslist, #autocomplete').bind('keyup', function() {
            if(allFilled()) $('#continue').removeAttr('disabled');
        });

$('#firstname, #surname, #addresslist, #autocomplete').keyup();

我改变了原来的:$'firstname,姓氏,addresslist,autocomplete'。绑定'keyup',函数。正确吗?在设置输入字段的值之后,我应该把它放在哪里呢?根据JQuery文档,触发keyup的方法如下:$target.keyup;但是每次值都会改变吗?因为它是一个地址字段。不同的用户会有不同的地址,所以每次你应该只放你的相关代码时,值都会改变。我认为这都与tbh@JoseRojas有关