0

I need to check two checkboxes in my form which is displayed in a modal window. The problem is that if the modal shows up the status of my checkboxes is checked (proofed with JS see beneath) but the checkboxes aren't checked (visually).

(I just open the modal then check if the checkboxes are checked and while the alert window is open which tells me that the checkboxes are checked they are checked visually but after clicking 'ok' the checked status disappears (visually))

Here is my form:

<div id="dialog_create_news" title="Neue News erstellen">
    <p class="validateTips">Bitte alle Felder ausfüllen!</p>
    <form method="post" id="news_add" action="edit.php?action=news_add" accept-charset="utf-8">
        <table>
            <tr>
                <td>Newsletter:</td>
                <td><input type="checkbox" name="newsletter_news" class="news_newsletter" value="1" /></td>
            </tr>
            <tr>
                <td>Kommentare:</td>
                <td><input type="checkbox" name="comments_news" class="news_comments" value="1" /></td>
            </tr>
            <tr class="press_title">
                <td>Titel:</td>
                <td><input type="text" id="title_news" name="title_news" /></td>
            </tr>
            <tr class="press_text">
                <td></td>
                <td><textarea cols="50" rows="15" name="content_news" id="content_news"></textarea></td>
            </tr>
        </table>
        <input type="hidden" name="news_submit" value="true" />​​​​​​​​​​​​​​​​​
    </form>
</div>

This is my JS:

$("#add_news").button().click(function() {
    $( "#dialog_create_news" ).dialog( "open" );
    //Set checkboxes 'checked'  
    if ($("#dialog_create_news").dialog( "isOpen" ) === true) {
        $('.news_comments').prop('checked', true);
        $('.news_newsletter').prop('checked', true);
    }
    //Check if checkboxes are checked
    if( $('.news_comments').prop('checked')){
        alert('checked');
    }
    clear_form_elements('#news_add');
});

I am using:

<script type="text/javascript" src="js/jQuery_1_7_1.min.js"></script>
<script type="text/javascript" src="js/jQuery_ui_1.8.17.custom.min.js"></script>
JPM
  • 213
  • 4
  • 16
  • Lots of good information about 'checked' here: http://stackoverflow.com/questions/901712/check-checkbox-checked-property-using-jquery – pilotcam Oct 07 '12 at 13:16
  • 1
    You are calling the "clear_form_elements('#news_add');" method. Is this method used to clear the form elements? If it is than it may be the cause of the problem you are having. – Sahil Kapoor Oct 07 '12 at 13:41
  • Read this thread before posting here. The problem is that they are checked but its not visible for the user. The user would think its not checked but it should be by default. @Sahil Kapoor yes you are right. Never thought of it before. Problem solved :) Thanks – JPM Oct 07 '12 at 13:41

0 Answers0