如果填写了其他表单,则启用下拉列表

时间:2013-04-22 22:07:37

标签: jquery

enter code here我有一个包含许多字段的表单。我需要的是底部的下拉菜单,名称为“运输首选项”默认为disableD,直到填写2个或更多项目表格字段。填写2个文本字段,下拉列表将是启用。怎么做?我没有丝毫想法。任何帮助将不胜感激。另请注意:我对场地和安置者有限制。这是代码:

 <SCRIPT> $("#Glass_ASTRO_165WNT").on('change', function() {
       this.value = (!Number(this.value)) ? '' : Math.max(100, Math.min(999999, Number(this.value)));
        });

    //With reference to http://www.hagenburger.net/BLOG/HTML5-Input-Placeholder-Fix-With-jQuery.html
    // 1. Handle placeholders (in non-HTML5 compliant browsers).
    if(!supports_input_placeholder()) {
        $('[placeholder]').focus(function () {
            var input = $(this);
            if (input.val() == input.attr('placeholder')) {
                input.val('');
                input.removeClass('placeholder');
            }
        }).blur(function () {
            var input = $(this);
            if (input.val() == '' || input.val() == input.attr('placeholder')) {
                input.addClass('placeholder');
                input.val(input.attr('placeholder'));
            }
        }).blur();

        //2. Prevent placeholder values being submitted to form's action script
        $('[placeholder]').eq(0).closest('form').submit(function () {
            $(this).find('[placeholder]').each(function () {
                var input = $(this);
                if (input.val() == input.attr('placeholder')) {
                    input.val('');
                }


               });
            });
        }
    });</SCRIPT>

    <form name="amada" method="post" action="review.php"onSubmit="return validate.check(this)">

                  <div class="side1">
                  <article>
                        <h2>Silver Name Badges</h2>
                        <p class="subDetails">Min. Qty: 100 pcs <br>
                          Lead Time: 3 Weeks<br>
                        <img src="web-pics/name_badge.png" width="200" height="200" alt="badge" /><br>

                         Quantity:
                    <input type="text" default=min=100 placeholder="none" name="Silver_Name_Badges" id="Silver_Name_Badges" maxlength="10" style="width:50px" tabindex=1  >

                    </p>
                </article>


 <td valign="top"><select name="Ship_Preference" id="Ship_Preference" tabindex=20 >
       <option value="Partial Shipment">Partial Shipment</option>
       <option value="When All Items Ready">Ship When All Items Ready</option>
       </select></td>
 <td valign="top"><select name="Ship_Preference" id="Ship_Preference" tabindex=20 >
       <option value="Partial Shipment">Partial Shipment</option>
       <option value="When All Items Ready">Ship When All Items Ready</option>
       </select></td>

1 个答案:

答案 0 :(得分:0)

一种可能的解决方案是在输入元素的内容发生变化时触发事件。触发事件时,您可以检查表单中填充的输入元素数(或换句话说,返回非空value属性)。像这样:

// Listen for 'input' events on all elements (that are not buttons)
// within the form named 'amada'
$("form[name='amada'] input[type!='button']").on("input", function(){
    // Count the number of inputs within this form that are not populated
    if($("form[name='amada"] input[value!=''][type!='button']").length >= 2){
        // If at least 2 populated inputs, enable the "Ship_Preference" select box
        $("select[name='Ship_Preference']").removeAttr("disabled");
    }else{
        // Otherwise, disable it.
        $("select[name='Ship_Preference']").attr("disabled", "disabled);
    }
})

请注意,type!="button"过滤器会从选区中删除按钮。如果这与您的代码无关,请将其删除。

另请注意,每当插入一个字符时,“输入”事件(我从this answer偷走)都会触发,而“更改”事件只会在输入框失去焦点时才会触发。我认为这是理想的行为,但你可以尝试看看你喜欢哪种行为。

希望有所帮助。