I am attempting to build a small application where our editors can choose to hide some elements, in this case, Job Names, from a page when it is printed.
However, I cannot seem to get the addclass to work properly. It either does nothing or it adds the class to every checkbox.
To give my checkboxes a unique id, I am using the job name as the ID in php. These come from a database. Input:
<input type='checkbox' id='".$row['name']"'/><div class='tohide ".$row['name']."'>".$row['name']."</div>
Javascript:
var src = <?php echo json_encode($row['name']); ?>;
$('input#src').change(function(){
if(this.checked){
$('.tohide').addClass('bold noprint');
}else{
$('.tohide').removeClass('bold noprint');
}
})
I have noticed that <?php echo json_encode($row['name']); ?> and <?php echo $row['name']; ?> do not give any results. I am using the same $row['name'] inside the php to generate proper ID'd for the checkboxes.
Client Side code:
<script type="text/javascript">
var src = "";
$('input#'+ src).change(function(){
if(this.checked){
$('.tohide').addClass('bold noprint');
}
else {
$('.tohide').removeClass('bold noprint');
}
})
</script>
When using json_encode I do get a value of null