Skip to content
Advertisement

How to execute script only after button onclick?

I have a script that auto-replaces specific characters like double spaces into single space and straight quotes into smart quotes in the textarea

However, when I try to add onclick feature, it’s not working for me, it’s still executing it before the click of a button (the moment it detects the character).

Here’s what my it looks like right now:

JavaScript
JavaScript

I really want it to work only after the user clicks the button, and not auto-replace before it. Please tell me how to fix this bug?

Advertisement

Answer

your function that replaces the content of the textarea is called in a input listener, so you should get it out in a separate function and call that function in the fixText function

JavaScript
JavaScript
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement