/    Sign up×
Community /Pin to ProfileBookmark

Sorry I do not know java very well so here is my dilemma, changing the font tag in this does not work.

[CODE]<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Strict//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd”>
<html xmlns=”http://www.w3.org/1999/xhtml” xml:lang=”en-gb”>
<head>
<meta http-equiv=”Content-type” content=”text/html; charset=US-ASCII” />
<title>Textarea Pseudo-Tag Insertion Demo</title>
<script type=”text/javascript”>
function getSelection(ta)
{ var bits = [ta.value,”,”,”];
if(document.selection)
{ var vs = ‘#$%^%$#’;
var tr=document.selection.createRange()
if(tr.parentElement()!=ta) return null;
bits[2] = tr.text;
tr.text = vs;
fb = ta.value.split(vs);
tr.moveStart(‘character’,-vs.length);
tr.text = bits[2];
bits[1] = fb[0];
bits[3] = fb[1];
}
else
{ if(ta.selectionStart == ta.selectionEnd) return null;
bits=(new RegExp(‘([x00-xff]{‘+ta.selectionStart+’})([x00-xff]{‘+(ta.selectionEnd – ta.selectionStart)+’})([x00-xff]*)’)).exec(ta.value);
}
return bits;
}

function matchPTags(str)
{ str = ‘ ‘ + str + ‘ ‘;
ot = str.split(/[[B|U|I].*?]/i);
ct = str.split(/[/[B|U|I].*?]/i);
return ot.length==ct.length;
}

function addPTag(ta,pTag)
{ bits = getSelection(ta);
if(bits)
{ if(!matchPTags(bits[2]))
{ alert(‘ttInvalid SelectionnSelection contains unmatched opening or closing tags.’);
return;
}
ta.value = bits[1] + ‘<‘ + pTag + ‘>’ + bits[2] + ‘</’ + pTag + ‘>’ + bits[3];
}
}

function addPColor(ta,colornow)
{

bits = getSelection(ta);
if(bits)
{ if(!matchPTags(bits[2]))
{ alert(‘ttInvalid SelectionnSelection contains unmatched opening or closing tags.’);
return;
}
ta.value = bits[1] + ‘< font=”‘ + colornow + ‘”>’ + bits[2] + ‘</font>’ + bits[3];
}
}
</script>

<style type=”text/css”>
</style>
</head>

<body>
<form action=”thisform.cgi” name=”thisform”>

<fieldset>
<select size=”1″ name=”fontcolor” class=”textbox_skin” onchange=”addPColor(document.getElementById(‘text’)),thisform.fontcolor.options[this.selectedIndex].value” id=”fontcolor”>
<option selected value=””>Text Color</option>
<option value=”black”>Black</option>
<option value=”white”>White</option>
<option value=”yellow”>Yellow</option>
<option value=”red”>Red</option>
<option value=”blue”>Blue</option>
<option value=”green”>Green</option>
<option value=”orange”>Orange</option>
<option value=”purple”>Purple</option>
<option value=”brown”>Brown</option>
<option value=”pink”>Pink</option>
<option value=”gray”>Gray</option>
</select>
<button onclick=”addPTag(document.getElementById(‘text’),’b’)”><b>Bold</b></button>
<button onclick=”addPTag(document.getElementById(‘text’),’i’)”><i>Italic</i></button>
<button onclick=”addPTag(document.getElementById(‘text’),’u’)”><u>Underline</u></button>
</fieldset>
<textarea id=”text” rows=”20″ cols=”80″>
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Duis suscipit ultricies tortor. Morbi auctor, sapien ut posuere porta, magna nisl tempus leo, ut dictum ipsum sem non odio. Pellentesque pharetra, velit quis molestie lacinia, quam sem interdum urna, vel aliquet dolor tellus eget massa. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vivamus in nibh. Donec non purus. Etiam ut sem sed quam dapibus porta. Nam consequat congue dolor. Morbi id felis. Aliquam nibh. Etiam sollicitudin, augue accumsan cursus adipiscing, est justo imperdiet neque, in gravida wisi neque at ante. Nulla at tortor. Donec elementum tristique pede. Mauris in erat. Nullam posuere sem et felis. Aliquam consequat bibendum ante. Sed vel magna in urna aliquet aliquet. Sed feugiat, lectus nec fringilla dignissim, elit diam tristique arcu, eu consequat erat augue eu nibh.</textarea>
</form>

</body>
</html>
[/CODE]

to post a comment
JavaScript

0Be the first to comment 😎

×

Success!

Help @cortecds spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.1,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,
)...