Bronzato
Bronzato

Reputation: 9362

Check my radio button by code and also trigger change event

I need to check my radio button manually like below. But the problem is that the event is not fired (when checked manually).

$(function () {
    // always check the 1st element
    $("input:radio[name=MatrixID]:first").attr('checked', true).click();
});

$('.editor-field > input[type=radio]').change(function () {
    // !!! not fired when checked by code!!??
    p.mustSave = true;
});

My question: how to check manually (by code) my radio button and also trigger change event?

My html:

            <p>
                <span class="editor-field">
                    <input name="MatrixID" id="MatrixID873" type="radio" checked="checked" value="873"/>
                </span>
            </p>  

Thanks a lot.

Upvotes: 0

Views: 2494

Answers (1)

Karl-Andr&#233; Gagnon
Karl-Andr&#233; Gagnon

Reputation: 33880

.click() trigger click event, but you are using change(). Try this instead :

$("input:radio[name=MatrixID]:first").prop('checked', true).trigger('change');

Upvotes: 2

Related Questions