How do you do html text encodes using JavaScript

How do you do html text encodes using JavaScript:



In this post we describe how to encode Text on web page by using JavaScript. In this Example we take two textbox one for take text by user and second for giving result.

HTML Encode and Decode with Javascript:

function encode(text)
 {
 Ref="0123456789abcdefghijklmnopqrstuvwxyz.-~ABCDEFGHIJKLMNOPQRSTUVWXYZ"
Result=""
for (Count=0; Count<text.length; Count++)
{
Char=text.substring (Count, Count+1);
Num=Ref.indexOf (Char);
EncodeChar=Ref.substring(Num+1, Num+2)
Result += EncodeChar
}
document.form1.result.value=Result
} 

Client side HTML encoding and decoding:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
    <script language="JavaScript">
<!-- Beginning of JavaScript Programer-

function encode(text)
 {
 Ref="0123456789abcdefghijklmnopqrstuvwxyz.-~ABCDEFGHIJKLMNOPQRSTUVWXYZ"
Result=""
for (Count=0; Count<text.length; Count++)
{
Char=text.substring (Count, Count+1);
Num=Ref.indexOf (Char);
EncodeChar=Ref.substring(Num+1, Num+2)
Result += EncodeChar
}
document.form1.result.value=Result
}
// - End of JavaScript - -->
    </script>
</head>
<body>
    <form name="form1" runat="server">
    <div align="center">
        <h1>
            HTML encoding or decoding content client side using Javascript.
        </h1>
        <br />
        <table border="2">
            <tr>
                <td>
                    Enter&nbsp; your word<td>
                        <input name="input" type="Text"><br>
                        <tr>
                            <td>
                                Encoding Result:<td>
                                    <input name="result" type="Text">
                                    <tr>
                                        <td>
                                            &nbsp;<td align="left">
                                                <input type="Button" value="submit" onclick="encode(this.form.input.value)" style="width: 130px;
                                                    height: 28px">
            &nbsp;</table>
    </div>
    </form>
</body>
</html>


Text encodes using JavaScript:

html text encodes using JavaScript
html text encodes using JavaScript

JavaScript HTML Encode and HTMLDecode functions:

Here are a few types of commands that methods are useful for. 
  • Date Methods - set variables to the clock time in a variety of ways.
  • Document Methods - Generate new documents on the fly.
  • Form Methods - select form items, send the cursor to text boxes and submit forms.
  • History Methods - Press the reader's 'Back' button and other tricks.
  • Window Methods - used to open and close new windows
  • MessageBox Methods - Alert, Prompt, and Confirm are all methods.
  • Text Methods - Define the look of your text variables before your display them.
  • Math Methods - sin, cos, round, random, absolute value, etc.

window.open method encoding or decoding content client side using JavaScript:

The window.open function can have three optional parameters.
  • A URL.
  • A title of new window
  • Options for the window's appearance and also including height and width.
Other Asp.net and JavaScript Related Post:



Comments

Popular posts from this blog