Smilie toevoegen in form
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<SCRIPT language=Javascript>
function bbcode_ins(fieldId, tag)
{
field=document.getElementById(fieldId);
if(tag=='b' || tag=='i' || tag=='u' || tag == 'php' || tag == 'code')
{
if (document.selection)
{
field.focus();
sel = document.selection.createRange();
sel.text = '[' + tag + '][/' + tag+']';
}
//MOZILLA/NETSCAPE/SAFARI support
else if (field.selectionStart || field.selectionStart == 0)
{
var startPos = field.selectionStart;
var endPos = field.selectionEnd;
field.focus();
field.value = field.value.substring(0, startPos)
+ '[' + tag + '][/' + tag+']'
+ field.value.substring(endPos, field.value.length);
}
}
else if(tag == 'img')
{
var path = prompt('Enter image path', 'http://');
if(!path)
{
return;
}
if (document.selection)
{
field.focus();
sel = document.selection.createRange();
sel.text = '[' + tag + ']' + path + '[/' + tag+']';
}
//MOZILLA/NETSCAPE/SAFARI support
else if (field.selectionStart || field.selectionStart == 0)
{
var startPos = field.selectionStart;
var endPos = field.selectionEnd;
field.focus();
field.value = field.value.substring(0, startPos)
+ '[' + tag + ']' + path + '[/' + tag+']'
+ field.value.substring(endPos, field.value.length);
}
}
else if(tag == 'url')
{
var url = prompt('Enter link URL', 'http://');
var linkText = prompt('Enter link text', '');
if(!url || !linkText)
{
return;
}
if (document.selection)
{
field.focus();
sel = document.selection.createRange();
sel.text = '[' + tag + '='+url+']' + linkText + '[/' + tag+']';
}
//MOZILLA/NETSCAPE/SAFARI support
else if (field.selectionStart || field.selectionStart == 0)
{
var startPos = field.selectionStart;
var endPos = field.selectionEnd;
field.focus();
field.value = field.value.substring(0, startPos)
+ '[' + tag + '='+url+']' + linkText + '[/' + tag+']'
+ field.value.substring(endPos, field.value.length);
}
}
}
</script>
<form>
<input type="button" onclick="bbcode_ins('comment', 'b')" value="B" style="width:15px;font-weight:bold;" />
<input type="button" onclick="bbcode_ins('comment', 'u')" value="_" style="width:15px;" />
<input type="button" onclick="bbcode_ins('comment', 'i')" value="I" style="width:15px;font-style:italic;" />
<input type="button" onclick="bbcode_ins('comment', 'img')" value="img" style="width:25px;" />
<input type="button" onclick="bbcode_ins('comment', 'url')" value="url" style="width:25px;" />
<input type="button" onclick="bbcode_ins('comment', 'php')" value="php" style="width:25px;" />
<input type="button" onclick="bbcode_ins('comment', 'code')" value="code" style="width:30px;" />
<input type="button" onclick="bbcode_ins('comment', ':)')" value=":)" style="width:30px;" />
<textarea name='comment' cols='45' rows='10' id="comment"></textarea>
</form>
function bbcode_ins(fieldId, tag)
{
field=document.getElementById(fieldId);
if(tag=='b' || tag=='i' || tag=='u' || tag == 'php' || tag == 'code')
{
if (document.selection)
{
field.focus();
sel = document.selection.createRange();
sel.text = '[' + tag + '][/' + tag+']';
}
//MOZILLA/NETSCAPE/SAFARI support
else if (field.selectionStart || field.selectionStart == 0)
{
var startPos = field.selectionStart;
var endPos = field.selectionEnd;
field.focus();
field.value = field.value.substring(0, startPos)
+ '[' + tag + '][/' + tag+']'
+ field.value.substring(endPos, field.value.length);
}
}
else if(tag == 'img')
{
var path = prompt('Enter image path', 'http://');
if(!path)
{
return;
}
if (document.selection)
{
field.focus();
sel = document.selection.createRange();
sel.text = '[' + tag + ']' + path + '[/' + tag+']';
}
//MOZILLA/NETSCAPE/SAFARI support
else if (field.selectionStart || field.selectionStart == 0)
{
var startPos = field.selectionStart;
var endPos = field.selectionEnd;
field.focus();
field.value = field.value.substring(0, startPos)
+ '[' + tag + ']' + path + '[/' + tag+']'
+ field.value.substring(endPos, field.value.length);
}
}
else if(tag == 'url')
{
var url = prompt('Enter link URL', 'http://');
var linkText = prompt('Enter link text', '');
if(!url || !linkText)
{
return;
}
if (document.selection)
{
field.focus();
sel = document.selection.createRange();
sel.text = '[' + tag + '='+url+']' + linkText + '[/' + tag+']';
}
//MOZILLA/NETSCAPE/SAFARI support
else if (field.selectionStart || field.selectionStart == 0)
{
var startPos = field.selectionStart;
var endPos = field.selectionEnd;
field.focus();
field.value = field.value.substring(0, startPos)
+ '[' + tag + '='+url+']' + linkText + '[/' + tag+']'
+ field.value.substring(endPos, field.value.length);
}
}
}
</script>
<form>
<input type="button" onclick="bbcode_ins('comment', 'b')" value="B" style="width:15px;font-weight:bold;" />
<input type="button" onclick="bbcode_ins('comment', 'u')" value="_" style="width:15px;" />
<input type="button" onclick="bbcode_ins('comment', 'i')" value="I" style="width:15px;font-style:italic;" />
<input type="button" onclick="bbcode_ins('comment', 'img')" value="img" style="width:25px;" />
<input type="button" onclick="bbcode_ins('comment', 'url')" value="url" style="width:25px;" />
<input type="button" onclick="bbcode_ins('comment', 'php')" value="php" style="width:25px;" />
<input type="button" onclick="bbcode_ins('comment', 'code')" value="code" style="width:30px;" />
<input type="button" onclick="bbcode_ins('comment', ':)')" value=":)" style="width:30px;" />
<textarea name='comment' cols='45' rows='10' id="comment"></textarea>
</form>
Welke browser? Al in de debug/ontwikkelaars console gekeken?
Maak er een aparte functie van (anders dekt de naam van de functie de lading niet meer).
Zoiets (ik heb zo veel mogelijk de code hergebruikt)
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
<script>
function insert_smiley(fieldId, tag)
{
var field=document.getElementById(fieldId);
if (document.selection)
{
field.focus();
sel = document.selection.createRange();
sel.text = tag ;
}
//MOZILLA/NETSCAPE/SAFARI support
else if (field.selectionStart || field.selectionStart == 0)
{
var startPos = field.selectionStart;
var endPos = field.selectionEnd;
field.focus();
field.value = field.value.substring(0, startPos)
+ tag
+ field.value.substring(endPos, field.value.length);
}
}
</script>
<input type="button" onclick="insert_smiley('comment', ':)')" value=":)" style="width:30px;" />
<textarea name='comment' cols='45' rows='10' id="comment"></textarea>
function insert_smiley(fieldId, tag)
{
var field=document.getElementById(fieldId);
if (document.selection)
{
field.focus();
sel = document.selection.createRange();
sel.text = tag ;
}
//MOZILLA/NETSCAPE/SAFARI support
else if (field.selectionStart || field.selectionStart == 0)
{
var startPos = field.selectionStart;
var endPos = field.selectionEnd;
field.focus();
field.value = field.value.substring(0, startPos)
+ tag
+ field.value.substring(endPos, field.value.length);
}
}
</script>
<input type="button" onclick="insert_smiley('comment', ':)')" value=":)" style="width:30px;" />
<textarea name='comment' cols='45' rows='10' id="comment"></textarea>
Gewijzigd op 17/10/2012 11:06:41 door Kris Peeters
Werkt perfect, bedankt !!