Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<script src="//code.jquery.com/jquery-1.9.1.min.js"></script><div><p>
String:
  
<textarea rows="4" cols="50"  name="normalTXT" id="normalTXT" >
</textarea>
<button onclick="convert()">Convert</button>
<br>
<URL>Encoding in URL: <input width="400" type="text" name="URL-ENCODE" id="URL-ENCODE"><br></URL>
<HTML>Encoding in HTML:<input type="text" name="HTML-ENCODE" id="HTML-ENCODE" ><br></HTML>  
 
function htmlEncode(value){
  //create a in-memory div, set it's inner text(which jQuery automatically encodes)
  //then grab the encoded contents back out.  The div never exists on the page.
  return $('<div/>').text(value).html().replace(/&/g,'%26');
}
function htmlDecode(value){
  return $('<div/>').html(value).text();
}
function convert(){
               
  var normalTxt = document.getElementById('normalTXT');
 
  var HTMLencoded = 
      (normalTxt.value);
  document.getElementById('HTML-ENCODE').value = HTMLencoded;
  
  var urlEncode  = htmlEncode(normalTxt.value);
  $("#URL-ENCODE").val(urlEncode);
            }
Output

This bin was created anonymously and its free preview time has expired (learn why). — Get a free unrestricted account

Dismiss x
public
Bin info
anonymouspro
0viewers