/    Sign up×
Community /Pin to ProfileBookmark

Please Help: Tag insertion Script always scrolls to top when tags are inserted

My tag insertion script is used to place tags into a text area around highlighted text when a button is pressed. For example…bold button would place bold tags around highlighted text.

[B]In Firefox only[/B]: If the textarea contains enough text that it has to scroll, the script no longer works properly.

If you scroll to the bottom of the textarea and press the bold button, it adds the tags; however, it also automatically scrolls to the very top of the textarea every time.

My codeis as follows:

[INDENT]<script type=”text/javascript”>
<!–
function formatText(el,tagstart,tagend) {
if (el.setSelectionRange) {
el.value = el.value.substring(0,el.selectionStart) + tagstart + el.value.substring(el.selectionStart,el.selectionEnd) + tagend + el.value.substring(el.selectionEnd,el.value.length)
}
else {
var selectedText = document.selection.createRange().text;

if (selectedText != “”) {
var newText = “<” + tag + “>” + selectedText + “</” + tag + “>”;
document.selection.createRange().text = newText;
}
}

}
//–>
</script>

<input type=”button” value=”bold” onclick=”formatText(document.getElementById(‘myta’),'<b>’,'</b>’)”/>
<br />
<textarea id=”myta” rows=”10″ cols=”30″></textarea>
<br />
<input type=”submit” value=”SUBMIT” />[/INDENT]

Is there any way to avoid this most annoying glitch?

Thank you ?

to post a comment
JavaScript

0Be the first to comment 😎

×

Success!

Help @mirra1515 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.17,
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: @nearjob,
tipped: article
amount: 1000 SATS,

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

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