Javascript replace every line of value -


so have script has find text on first textarea (right away when text pasted), replace 1 , give result textarea.

the problem it's replacing text first line. , want replace on lines.

my code: (doesn't work on jsfiddle, on html)

<script> function go() { var str = document.getelementbyid("a").value; resa=str.replace("http://","www."); resb=resa.replace(".com",""); document.getelementbyid("b").value=resb; } </script>  <textarea rows="10" cols="140" onkeyup="go()" id="a"> </textarea>  <textarea rows="10" cols="140" onkeyup="go()" onclick="this.focus();this.select();" id="b"> </textarea> 

so if try enter https://google.com in every line right text on other textarea, in first line.

you need global replace.

var str = document.getelementbyid("a").value; var resa=str.replace(/http\:\/\//g,"www."); var resb=resa.replace(/\.com/g,""); 

Comments

Popular posts from this blog

javascript - jquery or ashx not working -

opencv - DataType<cv::detail::deriv_type>::depth what is it used for -

python 3.x - Mapping specific letters onto a list of words -