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>