0

I am currently working on a small script that allows people to insert BB-codes to edit their text. They are able to click a button (for example underline) and then the bb-code will appear at the end of the textfield-value.

How can i retrieve the current position of the cursor within the textarea and then parse the bb-code within? This is a small part of the code:

<script type="text/javascript">
function addu() {
var message = window.prompt("Enter the underlined text below:");
if (message != "" && message != "null" && message != "undefined") {
var newtext = document.editform.text.value;
newtext += "\[u\]" + message + "\[/u\]";
document.editform.text.value = newtext;
document.editform.text.focus();
}
}
</script>
<img src="ubutton.jpg" onClick="addu()" />
<form action="edit.php">
<textarea class="editarea" name="text" id="text" cols="100" rows="33"></textarea>
<input type="submit" name="savebutton" value="save" />
</form>

Does anyone have a suggestion?

~G

Edited by Graphix: n/a

2
Contributors
2
Replies
3
Views
8 Years
Discussion Span
Last Post by Graphix
0

Hi,

I have looked into the link but the code doesnt work in FF (first time ever that happend!) and works in IE. Although it does figure out which line and which column, it can't figure out what the current char is (and this is required if i want to substr the first part of the text, place a bb-code between, and then place the second part of the text next to it.)

~G

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.