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

261
Visualizações
RegExp logical problem with variables in javascript

we have some checkboxes and When each of the checkes comes true, a value will be added to a single textbox.

and when each of the checkes comes false, their own value will be deleted.

I hope I explained well.

any way... here is my code:

<script>
      function <?php echo $fff; ?>q(){
            document.getElementById('<?php echo $chid;  ?>').checked = false;
            var v;
            v=document.getElementById('<?php echo $lblid; ?>').innerText;
            var ab;
            ab=document.getElementById('ab').value;
            var t;
            let a = document.getElementById('<?php echo $idlevel; ?>').innerText;
            const b = document.getElementById('<?php echo $txtid; ?>').value;
            const c = '-' + b + '-' + a;
            var reg;
            reg= new RegExp(c, 'g');
            t=ab.replace(reg,'');
            document.getElementById('ab').value=t;
            document.getElementById('<?php echo $lblid; ?>').innerHTML='<?php echo $talent; ?>';
        }
</script>

I do know that it is not a clean code:)

btw ab is my textbox. and c is my value.

but problem is : reg= new RegExp(c, 'g'); part doesn't accept c as value.

it works when I do this:reg= new RegExp('word', 'g');

but it doesn't accept any variable.

pls help.

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

0

Try :

 const c = '-' + b + '-' + a;
 var newString = new String(c)
 var reg = new RegExp(newString, "g");
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