如果字段为空,则禁用按钮

时间:2014-03-04 08:34:08

标签: jquery

如果关联的字段项为空,我有一个禁用按钮。我需要的是,如果其中一个字段为空,则应禁用保存按钮。所以我需要在禁用保存按钮时添加其他字段。

现在只有字段项具有禁用和启用功能。有帮助吗?谢谢

<SCRIPT type="text/javascript">
$(document).ready(function()
{
$('input[type="text"]').change(function() 
{
var item = $("#item").val();
var msgbox = $("#status");

$.ajax({  
    type: "POST",  
    url: "check_ajax.php",  
    data: "item="+ item,
    success: function(msg){
    console.log(msg)    
   $("#status").ajaxComplete(function(event, request){
    if(msg == 'OK')
    {
        msgbox.html('<img src="avail/available.png" align="absmiddle">');
        $("#save").attr("disabled",false);
    }
    else 
    {  
        $("#save").attr("disabled",true);
        msgbox.html(msg);
    }
   });

   }

  });

return false;
});
});
</SCRIPT>

<form name="userinfo" id="userinfo">
        <table width="100%" border="0" cellpadding="4" cellspacing="0">

            <tr>
                <td colspan="2" align="right"><a href="#" id="close">Close</a></td>
            </tr>
            <tr>
            <td>Add New Item</td>
            </tr>
            <tr>
                <td>Category</td>
                <td><select name="cat_code" id="cat_code" onchange="GetChangedValue(this.value);" class="inputs" readonly="readonly">
                    <option value=""></option>
                    <?php
                    $result = $mysqli->query("SELECT * FROM category ORDER BY id");
                    while($row = $result->fetch_assoc())
                        {
                    echo "<option value='".$row['cat_code'].".".$row['letter']."'>".$row['category']."</option>";
                        }
                    ?>
                    </select>
                    <script>
                    $('[name="cat_code"]').change(function() {
                    $('[name="maincopy"]').val($(this).val().split(".")[0]);
                    if ($(this).val() == '') {
                    $("#item_code").val('');
                    } else {
                    //here you can specify what to do if the value is NOT 
                    }
                    });
                    </script>
                    <input type="hidden" name="maincopy" id="maincopy" value="" readonly="readonly">
                </td>
            </tr>
            <tr>
                <td>item Code</td>
                <td> <input type="text" name="item_code" id="item_code" value="" class="inputs" readonly="readonly"></td>
            </tr>
            <tr>
                <td>Item</td>
                <td><input type="text" name="item" id="item" value="" class="inputs" autocomplete="off"></td>
            </tr>
            <tr>
                <td></td>
                <td><span id="status" class="inputs"></span></td>
            </tr>
            <tr>
                <td align="right"></td>
                <td><input type="button" value="Save" id="save"><input type="button" value="Cancel" id="cancel"></td>
            </tr>
        </table>
</form>

1 个答案:

答案 0 :(得分:0)

试试这个

 $("#save").prop("disabled",false);