Character Conversions : Char « Language Basics « JavaScript DHTML






Character Conversions

<HTML>
<HEAD>
<TITLE>Character Codes</TITLE>
<SCRIPT LANGUAGE="JavaScript">
var isNav = (navigator.appName == "Netscape")

var isNav4 = (isNav && parseInt(navigator.appVersion == 4))

function showCharCode() {
    if (isNav) {
        var theText = document.getSelection()
    } else {
        var theText = document.selection.createRange().text
    }
    if (theText) {
        document.forms[0].charCodeDisplay.value = theText.charCodeAt()
    } else {
        document.forms[0].charCodeDisplay.value = " "
    }
}
function showString(form) {
    form.result.value = String.fromCharCode(form.entry1.value,
form.entry2.value,form.entry3.value)
}

if (isNav4) {
    document.captureEvents(Event.MOUSEUP)
}
document.onmouseup = showCharCode
</SCRIPT>
</HEAD>
<BODY>
<B>Capturing Character Codes</B>
<FORM>
Select any of this text, and see the character code of the first character.<P>
Character Code:<INPUT TYPE="text" NAME="charCodeDisplay" SIZE=3><BR>
<HR>
</FORM>
</BODY>
</HTML>


           
       








Related examples in the same category

1.Displaying a String Containing Escaped Quotations
2.Using Special Characters in JavaScript
3.Defining Special Characters as Variables for Later Use
4.Using Special Formatting Characters