Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6470437
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T06:06:41+00:00 2026-05-25T06:06:41+00:00

I have this jquery function to automatically replace sertain characters with others: jQuery(function() {

  • 0

I have this jquery function to automatically replace sertain characters with others:

jQuery(function() {
    jQuery('.textarea').keyup(function() {

    jQuery(this).val(jQuery(this).val().replace(/A/g, "5"));
    jQuery(this).val(jQuery(this).val().replace(/Q/g, "3"));

    });
});

I want to make this function optional and only activated if the user clicks on a button next the text-area input form.

I’m trying something like this:

$("a").toggle(
  function () {

        jQuery(function() {
            jQuery('.tifibox').keyup(function() {

            jQuery(this).val(jQuery(this).val().replace(/A/g, "3"));
            jQuery(this).val(jQuery(this).val().replace(/Q/g, "5"));

            });
        });

    $(this).addClass("selected"); // button selected
  },
  function () {
    $(this).removeClass("selected");
  }
);

I have not tested this yet.. but is that correct? thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T06:06:41+00:00Added an answer on May 25, 2026 at 6:06 am

    Change the link to a checkbox and then you can use something like:

    $("#checkOne").change(   function () {
          if($(this).is(":checked")) {
             $("#textOne").bind("keyup", function() {
                  $(this).val($(this).val().replace(/A/g, "3"));
             });
          } else {
              $("#textOne").unbind("keyup");
          }   }
    
    );
    

    The jsfiddle

    This code will only replace newly typed text and old text will remain unchanged.
    If you want to replace the existing text (i.e. escape the existing text, modify the code as follows:

    $("#checkOne").change(
      function () {
          var textarea = $("#textOne");
          if($(this).is(":checked")) {
             escapeText($(textarea));
             $(textarea).bind("keyup", function() {
                  escapeText($(this));
             });
          } else {
              $(textarea).unbind("keyup");
          }
      }
    
    );
    
    function escapeText(ele) {
        $(ele).val($(ele).val().replace(/A/g, "3"));
    }
    

    the jsfiddle

    Of course you can use a link as well, but the syntax is confusing. toggle() takes 3 parameters (3 functions):

    1 – handler(eventObject)A function to execute every even time the element is clicked.

    2 – handler(eventObject)A function to execute every odd time the element is clicked.

    3 – handler(eventObject)Additional handlers to cycle through after clicks.

    So in your code above, the first click would call the second function (since one it’s odd) the second you call the first function. So turn on the feature in the second function and turn it off in the first.

    Also use bind and unbind as I have shown rather than setting classes.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this jQuery which works fine $(li[id^='shop_id']).click( function () { alert(I clicked on
I have this jQuery code that queries an API on a keyup event (via
I have this code in jQuery, that I want to reimplement with the prototype
have a function in jquery to automatically create the tab elements for a product
I have this code : jQuery('#btSave').click(function (event) { var jqxhr = $.post(Controller/Action, { lastName:
I have this jQuery click event $('#sidebar .nav a span').click(function () { var sidebar_nav
I have this JQuery code: $(div.notification).live(click, function(){ window.location=$(this).find(a).attr(href); var myId = $(this).attr(id); $.post(/videos/selected_notification.js, myId);
I have this bit of javascript written with jQuery 1.2.5. It's contained inside the
I have this code: var $msg = jQuery('<div></div>') .hide() .appendTo(document.body) ; if ($msg.is(:hidden)) {
I have this strange issue with my web app. You see, I'm using jQuery

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.