addplface.js 1.2 KB

12345678910111213141516171819202122232425262728293031
  1. function eaddplface(tag) {
  2. var myField;
  3. if (document.getElementById('saytext') && document.getElementById('saytext').type == 'textarea') {
  4. myField = document.getElementById('saytext');
  5. }
  6. else {
  7. return false;
  8. }
  9. if (document.selection) {
  10. myField.focus();
  11. sel = document.selection.createRange();
  12. sel.text = tag;
  13. myField.focus();
  14. }
  15. else if (myField.selectionStart || myField.selectionStart == '0') {
  16. var startPos = myField.selectionStart;
  17. var endPos = myField.selectionEnd;
  18. var cursorPos = endPos;
  19. myField.value = myField.value.substring(0, startPos)
  20. + tag
  21. + myField.value.substring(endPos, myField.value.length);
  22. cursorPos += tag.length;
  23. myField.focus();
  24. myField.selectionStart = cursorPos;
  25. myField.selectionEnd = cursorPos;
  26. }
  27. else {
  28. myField.value += tag;
  29. myField.focus();
  30. }
  31. }