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

241
Views
Change value input onclick witch setTimeout

How can I remove special symbols (R$) when clicking the button, or simply remove if it exists?

setTimeout(function clean() {
var input = document.getElementById('value')
input.value = input.value.replace(/[!$(){}[\]:;R<+?\\>]/g,'')
},3000)

I would like that when clicking on the button, it would also remove the symbol R$

I have so far

setTimeout(function clean() {
var input = document.getElementById('value')
onclick = input.value = input.value.replace(/[!$(){}[\]:;R<+?\\>]/g,'')
}, 2000)
<input id="value" name="item_valor" value="R$ 14,99" >
remover simbolo pagseguro
<br>

<button class="" onclick="clean()">clean</button>

about 4 years ago · Santiago Gelvez
2 answers
Answer question

0

Just use the String.replace() method and then the String.trim() method to ensure there are no leading or trailing spaces left behind..

const input = document.getElementById("value");
document.querySelector("button").addEventListener("click", function(){
  input.value = input.value.replace("R$","").trim();
});
<input id="value" name="item_valor" value="R$ 14,99" >
remover simbolo pagseguro
<br>

<button>clean</button>

about 4 years ago · Santiago Gelvez Report

0

Your regex for removing the special symbol is right, only error was of setTimeout & function declaration error.

I have fixed that code error.

Below snippet will work, but in function clean() it will wait for 1000ms because of setTimeout function.

function clean() {
  setTimeout(()=>{
    var input = document.getElementById('value')
    onclick = input.value = input.value.replace(/[!$(){}[\]:;R<+?\\>]/g,'');
    input.value = input.value.trim();
  }, 1000) // code inside setTimeout function will wait 1000ms to execute
}
<input id="value" name="item_valor" value="R$ 14,99" >
remover simbolo pagseguro
<br>

<button class="" onclick="clean()">clean</button>

about 4 years ago · Santiago Gelvez 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!