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 6720779
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T09:15:08+00:00 2026-05-26T09:15:08+00:00

I’m creating a really Find/Replace System but one of the main features are not

  • 0

I’m creating a really Find/Replace System but one of the main features are not working.

What’s Supposed to happen:

Once you search all words found will highlight on the page. I want it so you can click it and it opens an Div saying: Replace {WORD HERE} with {INPUT} and then you can hit replace and it will replace that word with the text in the Input.

I’m using the findAndReplace Plugin and I don’t want to change that.

What wont work:

Once you click on the word, the box opens, but I dont know how to make the found text replace with the one in the Input. Some of my code is in an One Line formate because I have:

return 'Code Here';

My Javascript:

shortcut.add("Ctrl+F", function() {
    $('#finder').animate({
        'bottom': '-53px'
    }, 100);
});
shortcut.add("Shift+F", function() {
    $('#finder').animate({
        'bottom': '0px'
    }, 100);
});
shortcut.add("Ctrl+C", function() {
    $('#finder').animate({
        'bottom': '-150px'
    }, 100);
});

function findAndReplace(searchText, replacement, searchNode) {
    if (!searchText || typeof replacement == '') {
        $('.r').css({
            'background': 'white',
            'color': 'black'
        });
        return;
    }
    if (!searchText || typeof replacement === 'undefined') {
        alert('No Items Found');
        $('.r').css({
            'background': 'white',
            'color': 'black'
        });
        return;
    }
    var regex = typeof searchText === 'string' ? new RegExp(searchText, 'g') : searchText,
        childNodes = (searchNode || document.body).childNodes,
        cnLength = childNodes.length,
        excludes = 'html,head,style,title,link,meta,script,object,iframe';
    while (cnLength--) {
        var currentNode = childNodes[cnLength];
        if (currentNode.nodeType === 1 && (excludes + ',').indexOf(currentNode.nodeName.toLowerCase() + ',') === -1) {
            arguments.callee(searchText, replacement, currentNode);
        }
        if (currentNode.nodeType !== 3 || !regex.test(currentNode.data)) {
            continue;
        }
        var parent = currentNode.parentNode,
            frag = (function() {
                var html = currentNode.data.replace(regex, replacement),
                    wrap = document.createElement('div'),
                    frag = document.createDocumentFragment();
                wrap.innerHTML = html;
                while (wrap.firstChild) {
                    frag.appendChild(wrap.firstChild);
                }
                return frag;
            })();
        parent.insertBefore(frag, currentNode);
        parent.removeChild(currentNode);
    }
}
$('#find').submit(function() {

    findAndReplace(document.getElementById('fText').value, function(hi) {
        var n = Math.floor(Math.random() * 9999999999);
        var o = Math.floor(Math.random() * 9999999999);
        var c = 'background:white;color:black;cursor:default;';
        var id = 'changer' + n + '';
        var onclick = "$('#replace_box" + n + "').slideDown();$('#black" + n + "').show();";
        var close = "$('#replace_box" + n + "').remove();$('#black" + n + "').remove();$('#highlight" + n + "').css({'background' : 'white', 'color':'black'});";
        var click = "$('.black').hide();$('#replace_box" + n + "').slideUp(900).delay(4000).remove();$('#highlight" + n + "').html('<span id=" + id + " style=" + c + "></span>');"
        return '<div id="black' + n + '" class="black"></div><span id="highlight' + n + '" class="r" style="background: yellow;color: black;cursor:pointer;position:relative;" onclick="' + onclick + '">' + hi + '<div id="replace_box' + n + '" class="box" style="position:absolute;top:77px;left:116px;"><div style="position:relative;"><div class="close" onclick="' + close + '">Close</div>Replace <b>' + hi + '</b> with <input id="input' + n + '" autocomplete="off"/><br><br><button id="buttons' + n + '" onclick="' + click + '">Replace!</button><div class="chat-bubble-arrow"></div><div class="chat-bubble-arrow-border"></div></div></div></span>';
    });
    return false;
});
$('#replace').submit(function() {
    findAndReplace(document.getElementById('fText').value, function() {
        var mon = $('#rText').val();
        return '<span class="highlight2" style="background: white;color: black;">' + mon + '</span>';
    });
    return false;
});

Oh, and I’m using the Shortcut plugin to make the find Box show on CTRL+F (Replacing the Browser Find System)

Note in the Javascript this is the main code for the Find:

 $('#find').submit(function() {

        findAndReplace(document.getElementById('fText').value, function(hi){
        var n = Math.floor(Math.random() * 9999999999); 
        var o = Math.floor(Math.random() * 9999999999); 
        var c = 'background:white;color:black;cursor:default;';
        var id = 'changer'+n+'';
        var onclick = "$('#replace_box"+n+"').slideDown();$('#black"+n+"').show();";
        var close = "$('#replace_box"+n+"').remove();$('#black"+n+"').remove();$('#highlight"+n+"').css({'background' : 'white', 'color':'black'});";
        var click = "$('.black').hide();$('#replace_box"+n+"').slideUp(900).delay(4000).remove();$('#highlight"+n+"').html('<span id="+id+" style="+c+"></span>');"
        return '<div id="black'+n+'" class="black"></div><span id="highlight'+n+'" class="r" style="background: yellow;color: black;cursor:pointer;position:relative;" onclick="'+onclick+'">' + hi + '<div id="replace_box'+n+'" class="box" style="position:absolute;top:77px;left:116px;"><div style="position:relative;"><div class="close" onclick="'+close+'">Close</div>Replace <b>'+hi+'</b> with <input id="input'+n+'" autocomplete="off"/><br><br><button id="buttons'+n+'" onclick="'+click+'">Replace!</button><div class="chat-bubble-arrow"></div><div class="chat-bubble-arrow-border"></div></div></div></span>';
       });
       return false;
   });

Here is my HTML:

<div id="finder">  
<div style="position:relative;">
<form id="find" style="padding-bottom:10px;">
  <button class="close2" id="wa" onclick="$('#finder').animate({'bottom' : '-150px'}, 100);">X</button>
  <input id="fText" placeholder="Enter Text you wanna replace here!" autocomplete="off" style="width:210px;"/>
  <button>Find!</button>
</form>
<form id="replace">
  <input id="rText" placeholder="Replace all of the found items." autocomplete="off" style="width:210px;"/>
  <button>Replace All</button>
</form>
</div>
</div>
<div class="black"></div>
<div id="show"></div><div id="test"></div>
<div id="boxes"></div>

I also have CSS But I won’t be posting that here.

My Example Is here:

Find/Replace

Really hope someone can understand the way I code and can help.

  • 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-26T09:15:09+00:00Added an answer on May 26, 2026 at 9:15 am

    Here is your code for the “Replace” button that appears when you click on a highlighted word:

    <button id="buttons7430059098" onclick="$('.black').hide();$('#replace_box7430059098').slideUp(900).delay(4000).remove();$('#highlight7430059098').html('&lt;span id=changer7430059098 style=background:white;color:black;cursor:default;&gt;&lt;/span&gt;');">Replace!</button>
    

    What it is doing is replacing the contents of the highlighted element with an empty span. You need to actually put whatever the user typed into the input field ($("#input7430059098").val()) into that span.

    I would also create a function that can be called from the click handler of the button to do the replacement, as there already seems to be a lot of code right in the click handler, but that’s just me.

    Edit:

    Try this:

    var click = "$('.black').hide();$('#replace_box"+n+"').slideUp(900).delay(4000).remove();$('#highlight"+n+"').html('<span id="+id+" style="+c+">' + $('#input" + n + "').val() + '</span>');";

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

Sidebar

Related Questions

Seemingly simple, but I cannot find anything relevant on the web. What is the
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
Is it possible to replace javascript w/ HTML if JavaScript is not enabled on
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I am reading a book about Javascript and jQuery and using one of the
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this

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.