Iterate array in input element

1

I need to generate a radio element according to the selection of a field. I'm having difficulty building the block:

I need to fill in the value of radius in this block according to the section of the array below:

var horario = ['quinta/10:00:00', 'quinta/21:00:00','sexta/10:00:00','domingo/15:00:00']; 

 <div id="valores">
    <input class="sr-only" name="dias" type="checkbox" value="" ><span class="checkbox-label">
    </span></input>
</div>
    
asked by anonymous 23.06.2017 / 23:21

1 answer

1

You can do this by creating the inputs with HTML strings in JavaScript:

var horario = ['quinta/10:00:00', 'quinta/21:00:00', 'sexta/10:00:00', 'domingo/15:00:00'];

var inputs = horario.map(function(h) {
  return [
    '<input class="sr-only" name="dias" type="checkbox" value="', h, '" />',
    '<span class="checkbox-label">', h, '</span>'
  ].join('');
}).join('<br>');

document.getElementById('valores').innerHTML = inputs;
<div id="valores">

</div>
    
23.06.2017 / 23:31