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

221
Visualizações
multiple checkbox enabled display text, disabled remove text with javascript?

are these 2 functions possible using javascript (onclick checkbox to enabled then display text, onclick to disable and then undisplay text)?

  1. When ticking a checkbox and then display text (optionally editable). When unticking the same checkbox and removing the text?

  2. Having a series of such checkboxes and displaying (or undisplaying) each line of text in the order the checkboxes are listed? (eg 1 line at a time in the order of the checkboxes)

** EDIT - code so far, not working for other options... also is it possible to edit all the text in 1 container? ***

<!DOCTYPE html>
<html>
<body>
<p>Text Maker:</p>
<input type="checkbox" id="box" onclick="myFunction()">
<label for="box">Option 1</label> 
<input type="checkbox" id="box" onclick="myFunction()">
<label for="box">Option 2</label> 
<input type="checkbox" id="box" onclick="myFunction()">
<label for="box">Option 3</label> 

<p id="text" style="display:none">Display Option 1 settings here.</p>
<p id="text" style="display:none">Display Option 2 settings here.</p>
<p id="text" style="display:none">Display Option 3 settings here.</p>

<script>
function myFunction() {
  var checkBox = document.getElementById("box");
  var text = document.getElementById("text");
  if (checkBox.checked == true){
    text.style.display = "block";
  } else {
     text.style.display = "none";
  }
}
</script>
</body>
about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

You can use the this keyword when calling your function to reference the checkbox that is being clicked, and also pass in the paragraphs id to grab that element.

You can add contenteditable="true" to your paragraph tags to make them editable, if I understand you correctly?

<p>Text Maker:</p>
<input type="checkbox" id="box1" onclick="myFunction(this,'textBox1')">
<label for="box1">Option 1</label> 
<input type="checkbox" id="box2" onclick="myFunction(this,'textBox2')">
<label for="box2">Option 2</label> 
<input type="checkbox" id="box3" onclick="myFunction(this,'textBox3')">
<label for="box3">Option 3</label> 

<p id="textBox1" style="display:none" contenteditable="true">Display Option 1 settings here.</p>
<p id="textBox2" style="display:none">Display Option 2 settings here.</p>
<p id="textBox3" style="display:none">Display Option 3 settings here.</p>

<script>
function myFunction(checkBoxElm,textBoxId) {
 
  let textBox = document.getElementById(textBoxId);
  if (checkBoxElm.checked){
    textBox.style.display = "block";
  } else {
     textBox.style.display = "none";
  }
}
</script>
about 4 years ago · Juan Pablo Isaza Relatório

0

When having multiple inputs with the same identity class name works better. So you can add a class name to the inputs and then use each function to achieve what you are trying to do.

The following inputs are having the same class name and now you can use each function as follows:

`

$ = jQuery;
$('.box').each(function(){
            
    $(this).change(function() { // on change of any of the input either checked or unchecked

        if(this.checked){ // if the input is checked
             alert('checked'); // your css
        }else{ // if the input is unchecked
             alert('not checked'); // your css
        }

    });
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<input type="checkbox" class="box">
<label for="box">Option 1</label>
<input type="checkbox" class="box">
<label for="box">Option 2</label>
<input type="checkbox" class="box">

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