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