Reply
  #1  
Old 02-13-2010, 05:49 PM
JavaScriptBank JavaScriptBank is offline
Junior Medost
Points: 428, Level: 8
Activity: 99%
 

Join Date: Sep 2009
Posts: 61
Diggs: 0
Thanks: 0
Thanked 0 Times in 0 Posts
Default HTML to Entities script

This JavaScript converts special HTML characters to their entities version inside user entered data such as a TEXTAREA before the detail at JavaScriptBank.com - 2.000+ free JavaScript codes


How to setup

Step 1: Place JavaScript below in your HEAD section
JavaScript
Code:
<SCRIPT type=text/javascript>

// HTML to Entities (form) script- By JavaScriptKit.com (http://www.javascriptkit.com)
// For this and over 400+ free scripts, visit JavaScript Kit- http://www.javascriptkit.com/
// This notice must stay intact for use

function html2entities(){
var re=/[(<>"'&]/g
for (i=0; i<arguments.length; i++)
arguments[i].value=arguments[i].value.replace(re, function(m){return replacechar(m)})
}

function replacechar(match){
if (match=="<")
return "&lt;"
else if (match==">")
return "&gt;"
else if (match=="\"")
return "&quot;"
else if (match=="'")
return "'"
else if (match=="&")
return "&amp;"
}


</SCRIPT>
	<!--
    	This script downloaded from www.JavaScriptBank.com
    	Come to view and download over 2000+ free javascript at www.JavaScriptBank.com
	-->
Step 2: Place HTML below in your BODY section
HTML
Code:
<FORM><TEXTAREA style="WIDTH: 400px; HEIGHT: 100px" name=data1></TEXTAREA><BR>
<INPUT onclick=html2entities(this.form.data1) type=button value="Convert special chars to entities"> 
</FORM>
	<!--
    	This script downloaded from www.JavaScriptBank.com
    	Come to view and download over 2000+ free javascript at www.JavaScriptBank.com
	-->





Reply With Quote

Reply
  


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

Forum Jump


All times are GMT. The time now is 12:34 AM.


Powered by vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Mirror Web Services LLC Nepal, All Rights Reserved.