N
N
Neowaring Stalker2019-08-27 15:33:08
PHP
Neowaring Stalker, 2019-08-27 15:33:08

How to activate the radio switch after clicking on the option picture?

There is a radio switcher with pictures of the option
How to make the radio itself become selected after clicking on the IMG picture?
Here is the radio buttons code

product.php
<?php if ($option['type'] == 'radio') { ?>
                  <div class="form-group<?php echo ($option['required'] ? ' required' : ''); ?>">
                    <label class="control-label"><?php echo $option['name']; ?></label>
                    <div id="input-option<?php echo $option['product_option_id']; ?>">
                      <?php foreach ($option['product_option_value'] as $option_value) { ?>
                      <div id="pp_options_radio"  class="radio">
                        <label>
                          <input type="radio" name="option[<?php echo $option['product_option_id']; ?>]" value="<?php echo $option_value['product_option_value_id']; ?>" class="pp_options"/>
                          <?php if ($option_value['image']) { ?>
                          <img src="<?php echo $option_value['image']; ?>" data-toggle="tooltip" data-placement="top" alt="<?php echo $option_value['name'] . ($option_value['price'] ? ' ' . $option_value['price_prefix'] . $option_value['price'] : ''); ?>" title="<?php echo $option_value['name'] . ($option_value['price'] ? ' ' . $option_value['price_prefix'] . $option_value['price'] : ''); ?>" class="img-thumbnail pp_img_options" />
                          <?php } ?>
                          <?php if ($option_value['price']) { ?>
                          (<?php echo $option_value['price_prefix']; ?><?php echo $option_value['price']; ?>)
                          <?php } ?>
                        </label>
                      </div>
                      <?php } ?>
                    </div>
                  </div>
                  <?php } ?>

Preferably with a third party script

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alex, 2019-08-27
@neowaring

<input id="item">
<img onclick="set('item')">
<script>
function set(id)
{
  $('#'+id).click();
}
</script>

S
Sergey, 2019-08-27
@Sponom

Add the id attribute to the input , and for the label add the attribute for="id of the input" Clicking on the label will switch the radio input, and accordingly, clicking on the img too . You can google more about the label tag and the for attribute)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question