Howto Select2 open value new window

Hi folks

How i can open all pages selected ? I try using

onclick="window.open(document.jump.param.options[document.jump.param.selectedIndex].value);

But opened only first value selected.

My code:

 <form class="kt-form kt-form--fit kt-form--label-right" name="jump">
          <div class="modal-body">
            <div class="form-group row">
              <label class="col-form-label col-lg-3 col-sm-12">Escolha as fichas para baixar</label>
              <div class="col-lg-9 col-md-9 col-sm-12">
                <select class="form-control kt-select2" id="kt_select2_3_modal" name="param" multiple="multiple">
                 @foreach ($produtos as $produto)
                 <option value="https://url.app/pdf/{{ $produto->cod }}">{{ $produto->cod }} - {{ $produto->nome }}</option>
                 @endforeach
               </select>
             </div>
           </div>
         </div>
         <div class="modal-footer">
          <button type="button" class="btn btn-brand" data-dismiss="modal">Fechar</button>
          <input type="button" class="btn btn-secondary" id="button" onclick="window.open(document.jump.param.options[document.jump.param.selectedIndex].value);" value="Get Files" />
        </div>
      </form>

Create a custom function which loops through your selected items and then trigger window.open for each.

<input type="button" class="btn btn-secondary" id="button" onclick="openLinks(document.jump.param.options[document.jump.param.selectedIndex].value)" value="Get Files" />


function openLinks(links) {
  links.forEach(link => window.open(link));
}

Keep in mind that popup blocking is a thing which might block your attempt to open a link to other domains.

image

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.