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

303
Vistas
Javascript/HTML - function replace letter in text area with variable value in input field

i'm trying to replace the "a" letter by a variable string into input field "INPUT1". So i would like, when i write a sentence in "textarea_up", it replace in "textarea_down" the letter a by input field (INPUT1) value.

Here is the code :

<textarea id="textarea_up"onkeyup="GetValue(); FunReplace();; Refreshcool();" type="text" name="filter_name" value="" rows="10" cols="75" ></textarea>

<textarea id="textarea_down" type="text" value="" rows="10" cols="75" readonly></textarea> 
<br>
<br>
a = <input type="text" onkeyup="RefreshCool()" id="INPUT1" name="name" required minlength="4" maxlength="8" size="10">
<p id="ShowText"></p>
<script>
    function GetValue() {
        field_up = document.getElementById("textarea_up");
        field_down = document.getElementById("textarea_down");
        document.getElementById("textarea_down").innerHTML = field_up.value;
    }
    
//document.getElementById("INPUT1").value = "test";
//document.getElementById("INPUT1").value = INPUT1.value;
    
    function RefreshCool() {
        document.getElementById("ShowText").innerHTML = INPUT1.value;
        VarTest = INPUT1.value;
    }
    VarTest = INPUT1.value;
    MapObj = {
            a: VarTest,
            b: "beet",
        };  
    
    function FunReplace() {
            VarChaine = field_up.value;
            VarRemp = new RegExp(Object.keys(MapObj).join("|"), "g");
            field_down.innerHTML = VarChaine.replace(VarRemp, function(matched) {
                return MapObj[matched];
            });
        }
</script>

If i put this line it's work but i can't change my value anymore.

document.getElementById("INPUT1").value = "test";

In fact i would like that but it doesnt't work :

document.getElementById("INPUT1").value = INPUT1.value;

Did i miss something ?
Thank you in advance for your help
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Refreshcool is wrongly written.

You should update the replacing string before modifying the text with it.

<textarea id="textarea_up"onkeyup="GetValue(); FunReplace();; Refreshcool();" type="text" name="filter_name" value="" rows="10" cols="75" ></textarea>

should be

<textarea id="textarea_up"onkeyup="GetValue(); RefreshCool(); FunReplace();" type="text" name="filter_name" value="" rows="10" cols="75" ></textarea>

Javascript is not passing VarTest as a reference, therefore modifying it inside RefreshCool won't change MapObj:

function RefreshCool() {
    document.getElementById("ShowText").innerHTML = INPUT1.value;
    MapObj.a = INPUT1.value;
}
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