Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

301
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!