Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

258
Vistas
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 Respuestas
Responde la pregunta

0

Try :

 const c = '-' + b + '-' + a;
 var newString = new String(c)
 var reg = new RegExp(newString, "g");
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda