login  Naam:   Wachtwoord: 
Registreer je!
 Scripts:

Scripts > JS > Formulieren > UBB (IE & FF compatibel)

UBB (IE & FF compatibel)

Auteur: WumTol - 23 juli 2005 - 19:09 - Gekeurd door: Dennis - Hits: 6508 - Aantal punten: 4.50 (6 stemmen)




Heel simpel UBB script.

2 functies, smile(veld, smile) en tag(veld, tag1, tag2).
Je kan tag2 leeglaten als hij hetzelfde moet zijn als tag1 (niet het geval bij url, zie voorbeeld)!

Voorbeelden

Smile:
<img src="smile.gif" OnClick="smile(formulier.testarea, ':)');">

Dikgedruk:
<input type="button" value="B" onClick="tag(formulier.testarea, 'b', '');">

Url:
<input type="button" value="URL" onClick="tag(formulier.testarea, 'url=http://', 'url');">

Code:
Sla op in een js-file, of zet tussen <script> </script>
  1. <!--
  2. function smile(veld, smile)
  3. {
  4. if (document.selection)
  5. {
  6. veld.focus();
  7. var selection = document.selection.createRange();
  8. selection.text = smile;
  9. }
  10. else if (veld.selectionStart || veld.selectionStart == '0')
  11. {
  12. var startPos = veld.selectionStart;
  13. var endPos = veld.selectionEnd;
  14.  
  15. veld.value = veld.value.substring(0, startPos)
  16. + smile + veld.value.substring(endPos, veld.value.length);
  17. }
  18. else
  19. {
  20. veld.value += smile;
  21. }
  22. }
  23.  
  24. function tag(veld, tag1, tag2)
  25. {
  26. if (!tag2)
  27. {
  28. tag2 = tag1;
  29. }
  30.  
  31. if (document.selection)
  32. {
  33. veld.focus();
  34. var selection = document.selection.createRange();
  35.  
  36. if(selection.text)
  37. {
  38. selection.text = "["+tag1+"]"+selection.text+"[/"+tag2+"]";
  39. }
  40. else
  41. {
  42. veld.value += "["+tag1+"] [/"+tag2+"]";
  43. }
  44. }
  45. else if (veld.selectionStart || veld.selectionStart == '0')
  46. {
  47. var startPos = veld.selectionStart;
  48. var endPos = veld.selectionEnd;
  49.  
  50. if (startPos != endPos)
  51. {
  52. veld.value = veld.value.substring(0, startPos)
  53. + "["+tag1+"]"
  54. + veld.value.substring(startPos, endPos)
  55. + "[/"+tag2+"]"
  56. + veld.value.substring(endPos, veld.value.length);
  57. }
  58. else
  59. {
  60. veld.value = veld.value.substring(0, startPos)
  61. + "["+tag1+"] [/"+tag2+"]"
  62. + veld.value.substring(endPos, veld.value.length);
  63. }
  64. }
  65. }
  66. //-->
Download code! Download code (.txt)

 Stemmen
Niet ingelogd.

 Reacties
Post een reactie
Lees de reacties (3)
© 2002-2024 Sitemasters.be - Regels - Laadtijd: 0.021s