Ive been fooling around with both Jquery and PHP and Im trying to setup a website for a sports team. I've created a custom post type called "Matches" and in there I've created two Custom Meta Boxes. One for the match details (IE home and away team) and one for match stats (goals, shots etc.). What I currently have is a (Is This Game Complete) checkbox that shows/hides the statistics options (that are in a Div #meta_box_stats) in the Meta Box Details (#dw_match_details).
The checkbox data value is saving but it isn't functioning quite properly. If it's checked as complete upon loading to edit and the value is set to 'on' it still won't show the stats meta box when I try to edit the post, I have to click it off and then click it on again. Here is my code (as brief as possible cause theres a lot going on).
This is working, as I've done a var_dump on check and it changes accordingly to on or off and either shows the check or not.
I want the stats to be hidden initially until the gamescore is entered. Once entered and checked as complete it should always show when you edit the page...I just cant figure out why it isnt.
Here is My script
<script type="text/javascript">
jQuery(document).ready(function($) {
$("#dw_match_stats").hide();
$('#dw_match_details').on('change', '#dw_complete', function() {
played = $(this).prop('checked');
if (played) {
$('#dw_match_stats').show();
} else {
$('#dw_match_stats').hide();
}
});
$('#dw_match_stats').change();
});
</script>
As mentioned the custom data value "dw_complete" is saving and changing properly.
EDIT: Here is some of the remaining code. I've essentially created two meta boxes, one called #dw_match_details which has the team selection and the checkbox on whether or not the game is complete.
<div id="dw_match_details" class="postbox ">
<div class="handlediv" title="Click to toggle"><br></div><h3 class="hndle"><span>Match Details</span></h3>
<div class="inside">
<?php
$values = get_post_custom( $post->ID );
$check = $values['dw_complete'][0];
?>
<input type="checkbox" id="dw_complete" name="dw_complete" <?php checked( $check, 'on', true ); ?> />
<label for="dw_complete">Is This Game Complete?</label>
Then I have my stats metabox.
<div id="dw_match_display" class="postbox">
<div class="inside">
<div id="dw_game_stats" class="tabs-panel">
<div width="50%" style="float:left;margin-right:10%;">
<strong>Goals Per Period:</strong>
<table>
<thead>
<tr>
<th> </th>
<th>1st</th>
<th>2nd</th>
<th>3rd</th>
<th>OT</th>
<th>Total</th>
</tr>
</thead>
</table>
</div>
That's the gist of it, I obviously have more information going on for the stats section but think it should be irrelevant. If you need me to post that I can or Ill put it in a PasteBin. Before I forget here are the two calls to create my meta boxes.
function dw_custom_meta_boxes_match() {
add_meta_box( 'dw_match_details', 'Match Details', 'dw_match_details', 'dw_match', 'normal', 'high' );
add_meta_box('dw_match_display', 'Match Statistics', 'dw_match_display', 'dw_match', 'normal', 'low' );
#dw_match_stats
and#dw_match_details
, but you didn't provide matching example markup. Can you edit your post to show all the relevant markup in the first box? The idea is to allow us to set up a test to test your code. We can't do that without all the relevant markup.#dw_match_stats
HTML is still not present. It is used in the jQuery call$('#dw_match_stats').change();
and there are several missing closing divs</div>
in the markup you provided. A screen shot of text would probably not be useful.