M
M
mrzgt2015-12-10 18:32:48
PHP
mrzgt, 2015-12-10 18:32:48

How can I make the first option in type="radio" in the array be selected by default?

There is an array

<?php foreach ($ar as $key => $value) { ?>
                <?php ($value ==  $valueq) ? $selected = ' active' : $selected=''; ?>
                <label for="<?php echo $id . '-' . $value; ?>" class="tleft">
                  <input type="radio" id="<?php echo $id . '-' . $value; ?>"  name="<?php echo $name; ?>" value="<?php echo $value; ?>" <?php if ($valueq == $value) { ?>checked="checked"<?php }?>>
                  <?php echo $key; ?>
                </label>
              <?php } ?>

How to make the first option in type="radio" be selected by default?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
romy4, 2015-12-10
@romy4

if the array has at least 1 element, $valueq = $ar[0]; and get

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question