HTML and CSS Reference
In-Depth Information
EXAMPLE 16.1 ( CONTINUED )
1
function seeEncoding(form){
var myString = form.input.value;
2
alert( escape(myString ));
}
3
function seeDecoding(form) {
var myString = form.input.value;
4
alert( unescape(myString) );
}
</script>
</head>
<body background="cookebg.jpg" >
<div align="center"><h2>URL Encoding </h2>
<form name="form1">
Type in a string of text:
<p>
<input type="text" name="input" size=40 />
</p><p>
<input type="button"
value="See encoding"
5
onClick="seeEncoding(this.form); "/>
</p><p>
<input type="button"
value="See decoding"
6
onClick="seeDecoding(this.form); "/>
</p>
</form>
</div>
</body>
</html>
EXPLANATION
1
A function called seeEncoding() is defined. It takes a reference to a form as its only
parameter.
2
The built-in escape() function is used to URI encode the string that was entered
as input by the user.
3
A function called seeDecoding() is defined. It takes a reference to a form as its only
parameter.
4
The built-in unescape() function is used to convert the URI encoded string back
into its original ASCII format.
5
When the user clicks this button, the onClick event is triggered and the encoded
string will appear in an alert dialog box.
6
When the user clicks this button, the onClick event triggers a function that will
decode the encoded string. See Figures 16.6 and 16.7.
Search WWH ::




Custom Search