function insertText(myField, myValue) { if (document.selection) { myField.focus(); sel = document.selection.createRange(); sel.text = myValue; } else if (myField.selectionStart || myField.selectionStart == '0') { var startPos = myField.selectionStart; var endPos = myField.selectionEnd; myField.value = myField.value.substring(0, startPos) + myValue + myField.value.substring(endPos, myField.value.length); } else { myField.value += myValue; } }
Penggunaan dari fungsi javascript diatas adalah sebagai berikut :
<a href="javascript:void(0);" onclick="insertAtCursor(document.smsMessage.textareaMessage, '%cust_name%');">%cust_name%</a> <form name="smsMessage" action="" method="post"> <textarea name="textareaMessage" cols="30" rows="3"></textarea> </form>
You must be logged in to post a comment.