A
A
Artem2020-05-13 15:43:03
PHP
Artem, 2020-05-13 15:43:03

How to set checked in the required 'input' for a specific form with its 'id'?

There is an array with values ​​'data = [ 5, 5, 5]' . There are also 3 forms with different 'id' in which the rating is . Based on the assessment, you need to fix the 5th radio button.

<input class="rating-input" id="mod1'" name="radio-rating" type="radio" value="1">
   <label class="rating-star" for="mod1" ></label>                    
<input  class="rating-input" id="mod2" name="radio-rating" type="radio" value="2">
   <label class="rating-star" for="mod2"></label>  
<input class="rating-input" id="mod3" name="radio-rating" type="radio" value="3">
   <label class="rating-star" for="mod3"></label>  
<input class="rating-input" id="mod4" name="radio-rating" type="radio" value="4">
   <label class="rating-star" for="mod4"></label>  
<input class="rating-input" id="mod5" name="radio-rating" type="radio" value="5">
   <label class="rating-star" for="mod5"></label>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ivan Ivanov, 2020-05-13
@shylov

<?php $checked = 5;
           $count = 5;
?>
<?php for($i = 1; $i <= $count; $i++): ?>
    <?php if($i == $checked):?>
    <input class="rating-input" id="mod<?=$i?>'" name="radio-rating" type="radio" value="<?=$i?>" checked>
    <label class="rating-star" for="mod<?=$i?>" ></label>
    <?php else:?>
    <input class="rating-input" id="mod<?=$i?>'" name="radio-rating" type="radio" value="<?=$i?>">
    <label class="rating-star" for="mod<?=$i?>" ></label>
    <?php endif;?>
<?php endfor;?>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question