Creating a formatted output for the text

A few days back I was thinking how does rich text formatting in emails or blogs work. Furthermore, one of my friends has started to create his own forum and so I decided to create something that would solve my problem and help him too…

To create this I was helped by my friend kartik (http://kar2905.wordpress.com) and one of senior Djay (http://djkaos.wordpress.com/). I am putting down my code here

<script type=’text/javascript’>

var chk=0;
var msg;
var msg1;
var str_final1;

function eve(styl)
{

msg = document.frm1.txt;
if(chk==0)
{
msg1 = new String(document.frm1.txt.value);
chk=1;
}

var str_mid = “<“+styl+”>”+(msg.value).substring(msg.selectionStart,msg.selectionEnd)+”</”+styl+”>”;
var str_sel = (msg.value).substring(msg.selectionStart,msg.selectionEnd);
str_final1 = msg1.replace(str_sel,str_mid);
msg1 = str_final1;
document.getElementById(‘res’).innerHTML = str_final1;
}

</script>

</head>

<body>

<form name=’frm1′>
<input type=’textarea’ name=’txt’>
<input type= ‘button’ name=’Go’ value=’Bold’ onClick=”eve(‘b’)” >
<input type= ‘button’ name=’Go1′ value=’Italics’ onClick=”eve(‘i’)” >
<input type= ‘button’ name=’Go2′ value=’Underline’ onClick=”eve(‘u’)” >
</form>
<div id=”res” ></div>

</body>

This is the code whuch I would like everyone to try and share with everyone and improve a lot on it for fun or any other purposes. Anyone who improves it works on it please post a comment with the newer code so that I too can know about your works and make improvements along with mine

PS it orks on firefox as of now only

<script type=’text/javascript’>
var chk=0;
var msg;
var msg1;
var str_final1;
function eve(styl)
{
alert(chk)
msg = document.frm1.txt;
if(chk==0)
{
msg1 = new String(document.frm1.txt.value);
chk=1;
}
var str_mid = “<“+styl+”>”+(msg.value).substring(msg.selectionStart,msg.selectionEnd)+”</”+styl+”>”;
var str_sel = (msg.value).substring(msg.selectionStart,msg.selectionEnd);
str_final1 = msg1.replace(str_sel,str_mid);
msg1 = str_final1;
document.getElementById(‘res’).innerHTML = str_final1;
} </script>
</head>
<body>
<form name=’frm1′>
<input type=’textarea’ name=’txt’>
<input type= ‘button’ name=’Go’ value=’Bold’ onClick=”eve(‘b’)” >
<input type= ‘button’ name=’Go1′ value=’Italics’ onClick=”eve(‘i’)” >
<input type= ‘button’ name=’Go2′ value=’Underline’ onClick=”eve(‘u’)” >
</form>
<div id=”res” border =1>MANU HERe<br /></div>
</body>
Advertisements

4 thoughts on “Creating a formatted output for the text

  1. Just want to say what a great blog you got here!
    I’ve been around for quite a lot of time, but finally decided to show my appreciation of your work!

    Thumbs up, and keep it going!

    Cheers
    Christian

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s