lundi 11 mai 2015

.prop('selected') not working, button is disabled all the time in jquery

I want to enable the the submit button once the status in the select field is selected.

<div class="close_req">
    <div class="req_status">
        <select id="status_update">
            <option value="status" selected="selected" disabled="disabled">Status</option>
            <option value="complete">Complete</option>
            <option value="pending">Pending</option>
        </select>
    </div>
    <div class="req_addcharges">
        <select id="additional_charges">
            <option value="charge">Additional Charges</option>
            <option value="complete">Yes</option>
            <option value="pending">No</option>
        </select>
    </div>
    <div class="additional_charge">
        <input type="text" id="add_price" name="add_price" placeholder="Enter the additional charge" />
    </div>
    <div class="task_desc">
        <textarea id="task" name="task" cols="10" rows="6" placeholder="Description of the task"></textarea>
    </div>
    <div class="task_complete">
        <input type="submit" id="complete" name="complete" value="Task Complete" />
    </div>
    </form>
</div>

Here is the jquery script i have tried

$(document).ready(function () {
    $("#complete").attr("disabled", "disabled");

    function updateFormEnabled() {
        if ($("#status_update").prop('selected', true)) {
            $("#complete").removeAttr('disabled');
        } else {
            $("#complete").attr('disabled', 'disabled');
        }
    }
});
$("#status_update").change(updateFormEnabled);

But the submit button is always disabled, I want the button to enabled once the status is selected in the select field. Can anyone please help me with this issue.

Aucun commentaire:

Enregistrer un commentaire