I want to send some special html character to a text field and then use javascript to return it in its original format: for example, if I sent "& pi" it would display "π" on the text input and when I use javascript to return it I should get "& pi", but I can get "π" and not "& pi". Please help, my code is as follows:
<script type="text/javascript"> function qpush(a) { document.getElementById('input').value += a; } function show(a) { alert(document.getElementById('input').value); } </script> <input type="text" id="input" /> <input type="button" onclick="qpush('π');" value="π" /> <input type="button" onclick="show()" value="go" />
Depending on what you need, you can do one of three options for you:
use javascript escape and unescape functions:
var escaped = escape ('π')//escaped = "% u03C0", unescape π
jQuery, html :
$( ''). (). HTML()
, . , , "data-" , html5 DOCTYPEs.
document.getElementById('input'). setAttribute ('data-originalValue', '& pi')
value , HTML.
value
getAttribute('value'), π π HTML, π .
getAttribute('value')
π
π
HTML DOM, HTML ( HTML XHR ).
, "π", HTML &pi;.
"π"
&pi;
, π, :
<button type="button" value="&pi;">π</button>
( , IE )
, , π .
Use this to replace all occurrences of a character:
document.getElementById('input').value.replace(/π/g,"π");