Menambahkan text pada di posisi cursor yang aktif di dalam TextArea


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>

Mari Berdiskusi Bersama

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s