Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

97
Visualizações
Javascript returning multiple checkbox values

I'm having some trouble trying to get multiple checkbox values. It currently is working, just not in the way I wanted/was hoping it would. Right now anything checked is appended to the bottom of the body and not inline with the function it was aiming to be inserted into.

I'm trying to avoid using JQuery or anything except JavaScript as it's all we've currently covered in our class.

function favMedia(media){
    var media = document.forms['mediapref']['media'].value;
    return media;
}
function pets(pet){
    var pet = document.getElementsByName('pets')
    for (var checkbox of pet){
        if (checkbox.checked)
        document.body.append(checkbox.value + ' ');
    }
}
function about(text){
    var info = document.forms['personal']['about'].value;
    return info;
}

function infoForm(media, pet, text){
    document.getElementById('infoset').innerHTML = favMedia(media) + "<br>" + pets(pet) + "<br>" + about(text);
}

Is there some way I can assign it just to a single variable to return and then throw into the last function?

Also please give me any tips or improvements on any aspect of the functions if you have any.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Put it in a string that you return from the function.

function pets(pet) {
  var pet = document.querySelector('[name="pets":checked');
  let selected = [...pet].map(p => p.value);
  return selected.join(', ');
}
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda