# Javascript replace string with chars

**URL:** <https://forum.kirupa.com/t/javascript-replace-string-with-chars/323553>\
**Category:** Uncategorized\
**Created:** [July 6, 2011, 4:19pm UTC](https://forum.kirupa.com/t/javascript-replace-string-with-chars/323553 "2011-07-06T16:19:51Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Biiim](https://avatars.discourse-cdn.com/v4/letter/b/bc79bd/32.png) [@Biiim](https://forum.kirupa.com/u/Biiim)\
**Post date:** [July 6, 2011, 4:19pm UTC](https://forum.kirupa.com/t/javascript-replace-string-with-chars/323553/1 "2011-07-06T16:19:51Z")

</div>

Hello,

I’ve been scouring for over an hour now and can’t find the answer anywhere.

what i want is i have a known url such as

[http://www.example.com/webpage.php?var1=1&var2=234](http://www.example.com/webpage.php?var1=1&var2=234)

which i have in an a tag object(obj.href)

data is then checked and upon success this link gets inserted to a database and the link is converted to another link

[http://www.example2.com/webpage.php?var1=200&var2=87935](http://www.example2.com/webpage.php?var1=200&var2=87935)

my problem now is using javascript to locate in a text version of the page(page source) the exact link “[http://www.example.com/webpage.php?var1=1&var2=234](http://www.example.com/webpage.php?var1=1&var2=234)” and replace all occurances with the new link.

i have tried a few different things but most of the things i find on this are about regexp converting any link

heres a simplified version of what im trying to do

```auto
<textarea id='textbox' style='height:50%;width:100%;'>http://www.example.com/webpage.php?var1=1&var2=234</textarea>
<div id='previewhtml'><a id='theObj' href='http://www.example.com/webpage.php?var1=1&var2=234'></a></div>
<a href='#' onclick="runReplace();return false;">run</a>
<script type='text/javascript'>
var theBox = document.getElementById('previewhtml');
var theCode = document.getElementById('textbox');
var obj = document.getElementById('theObj');
obj.responseText = 'http://www.example.com/webpage.php?var3=234&var4=variable';
//response from ajax
function runReplace(){
	theCode.value.replace(obj.href, obj.responseText);
}
</script>

```

im lost how to operate this replace function!
