this is my code:
<?php
if(!empty($wpjobus_resume_skills)) {
for ($i = 0; $i < (count($wpjobus_resume_skills)); $i++) {
?>
<div style="text-align: center;">
<span>20%</span>
<input style="width:50%; float: none" type='checkbox' class="checkedClass<?php echo $i; ?>" id='wpjobus_resume_skills[<?php echo $i; ?>][1]' name='wpjobus_resume_skills[<?php echo $i; ?>][1]' value='20%' class='slider_value'>
</div>
<div style="text-align: center;">
<span>40%</span>
<input style="width:50%; float: none" type='checkbox' class="checkedClass<?php echo $i; ?>" id='wpjobus_resume_skills[<?php echo $i; ?>][1]' name='wpjobus_resume_skills[<?php echo $i; ?>][1]' value='40%' class='slider_value'>
</div>
<div style="text-align: center;">
<span>60%</span>
<input style="width:50%; float: none" type='checkbox' class="checkedClass<?php echo $i; ?>" id='wpjobus_resume_skills[<?php echo $i; ?>][1]' name='wpjobus_resume_skills[<?php echo $i; ?>][1]' value='60%' class='slider_value'>
</div>
<div style="text-align: center;">
<span>80%</span>
<input style="width:50%; float: none" type='checkbox' class="checkedClass<?php echo $i; ?>" id='wpjobus_resume_skills[<?php echo $i; ?>][1]' name='wpjobus_resume_skills[<?php echo $i; ?>][1]' value='80%' class='slider_value'>
</div>
<div style="text-align: center;">
<span>100%</span>
<input style="width:50%; float: none" type='checkbox' class="checkedClass<?php echo $i; ?>" id='wpjobus_resume_skills[<?php echo $i; ?>][1]' name='wpjobus_resume_skills[<?php echo $i; ?>][1]' value='100%' class='slider_value'>
</div>
ok. I am storing my data in a post meta var wpjobus_resume_skills
. I want to only checked the inputs which contains a value. for example on 1st iteration of the for loop, the input with 80% value should be checked as i have 80% in my var $wpjobus_resume_skills[$i][1]
. In the second loop lets say 40% is saved then i want to only checked that 40% input.
screenshot: should be like this
this is what i am trying which checked all the values:
<?php
if( !empty($wpjobus_resume_skills[$i][1]) )
{
<script type="text/javascript">
jQuery('.checkedClass<?php echo $i; ?>').prop('checked', true);
</script>
}
any help would be appreciated.
my array: print_r($wpjobus_resume_skills);
Array
(
[0] => Array
(
[0] => C++
[1] => 40%
)
[1] => Array
(
[0] => Java
[1] => 60%
)
[2] => Array
(
[0] => Rails
[1] => 80%
)
[3] => Array
(
[0] => HTML 5
[1] => 100%
)
[4] => Array
(
[0] => Android
[1] => 20%
)
)
This worked for me:
adding this to the input tag <?php echo ($wpjobus_resume_skills[$i][1]=='100%')?'checked':'';?>
<input style="width:50%; float: none" type='checkbox' class="checkingtheclass checkedClass<?php echo $i; ?>" id='wpjobus_resume_skills[<?php echo $i; ?>][1]' name='wpjobus_resume_skills[<?php echo $i; ?>][1]' <?php echo ($wpjobus_resume_skills[$i][1]=='100%')?'checked':'';?> value='100%' class='slider_value'>