/    Sign up×
Community /Pin to ProfileBookmark

Place "[*]" at beginning of each new line in textarea

I am trying to make a bbcode editor. I have everything, except I want to add one more feature. When the list item button is click, it adds “[*]” to the beginning of the selection. Is there any way to add those same characters to the beginning of each new line of the selected text?

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@justinbarneskinOct 26.2009 — Consider something like this----
[code=html]<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<HTML>
<HEAD><TITLE>Mo3-40pm46</TITLE>
<META http-equiv=Content-Type content="text/html; charset=UTF-8">
<STYLE type=text/CSS>

</STYLE>
<SCRIPT type="text/javascript">
function ReplaceStuff(S,O,N){ var rx=new RegExp(O,'g'); S=S.replace(rx, N); return S}

function findBreaks(t){
if(navigator.appName=='Microsoft Internet Explorer'){
txv=escape(t.value);
var O='%0D%0A'; var N='%0D%0A%5B*%5D'
txv=ReplaceStuff(txv,O,N)
t.value=unescape(txv)
}
}

</SCRIPT>
<META content="MSHTML 6.00.2900.2963" name=GENERATOR></HEAD>
<BODY scroll="auto">

<textarea id="tx" onchange="findBreaks(this)" cols=10 rows=20>
a
b
c
d</textarea>
</BODY></HTML>[/code]
×

Success!

Help @sarathi 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 5.19,
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: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

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

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...