Menu
how can i set a an image link:
<a><img src=happysmilie.gif></a>
to add:
?
into a textarea like this one:
<textarea name=message rows=12 cols=30 wrap=soft></text>
in php?
Thanks
[i]Originally posted by Pittimann [/i]
[B]Hi!
For sure, you want to enable the user to insert the smilie. So do it client side. In js it is very easy to accomplish what you want, if you are satisfied with the smilie always being inserted at the end of the text already in the textarea by some browsers.
Due to my limited experience, I only know a way, how to insert it at cursor position in IE...
BTW - guess you know, that not the image is going to be inserted into the textarea, but the image tag. The image will then be visible when you deal with the user's input.
Cheers - Pit [/B][/QUOTE]
[code=php]
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Untitled</title>
<script language="JavaScript" type="text/javascript">
<!--
function insertSmilie(smilieName){
document.myForm.message.value=document.myForm.message.value+'<img src="'+smilieName+'.gif">';
document.myForm.message.focus();
}
//-->
</script>
</head>
<body>
<a href="javascript:insertSmilie('happysmilie')"><img src="happysmilie.gif"></a>
<form name="myForm">
<textarea name="message" cols="50" rows="6"></textarea>
</body>
</html>
[/code]
[i]Originally posted by Pittimann [/i]
[B]Hi!
Here the short version of code, always adding the tag at the end of the text in the textarea:
[code=php]
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Untitled</title>
<script language="JavaScript" type="text/javascript">
<!--
function insertSmilie(smilieName){
document.myForm.message.value=document.myForm.message.value+'<img src="'+smilieName+'.gif">';
document.myForm.message.focus();
}
//-->
</script>
</head>
<body>
<a href="javascript:insertSmilie('happysmilie')"><img src="happysmilie.gif"></a>
<form name="myForm">
<textarea name="message" cols="50" rows="6"></textarea>
</body>
</html>
[/code]
Does this help you a bit??
Cheers - Pit [/B][/QUOTE]
[i]Originally posted by Pittimann [/i]
[B]Hi!
On submit you will simply send the data somewhere (I don't know the action taken, when your form is submitted).
Assuming you use the stuff for - let's say - a guestbook or so, and you'll have the data stored in a database or a textfile (do you??). If so and you have the data beeing read by your (e.g.) guestbook.php and echoed them somewhere, then you will have the images...
Cheers - Pit [/B][/QUOTE]
[code=php]
<?php
echo "<html>";
echo "<head>";
echo "<LINK REL='stylesheet' TYPE='text/css' HREF='style.css'>";
echo "<title>Message Box</title>";
?>
<script>
// SMILY CODE
// MADE BY LUKE DYSON
// MAY NOT BE USED ANYWHERE!
function smiley() {
document.getElementsByTagName('textarea')[0].innerHTML+= ":)";
}
function annoyed() {
document.getElementsByTagName('textarea')[0].innerHTML+= ":-/ ";
}
function bad() {
document.getElementsByTagName('textarea')[0].innerHTML+= ":-[ ";
}
function blush() {
document.getElementsByTagName('textarea')[0].innerHTML+= ":@ ";
}
function cheesy() {
document.getElementsByTagName('textarea')[0].innerHTML+= ":D ";
}
function cool() {
document.getElementsByTagName('textarea')[0].innerHTML+= "8) ";
}
function huh() {
document.getElementsByTagName('textarea')[0].innerHTML+= "??? ";
}
function kiss() {
document.getElementsByTagName('textarea')[0].innerHTML+= ":-) ";
}
function roll() {
document.getElementsByTagName('textarea')[0].innerHTML+= "::) ";
}
function sad() {
document.getElementsByTagName('textarea')[0].innerHTML+= ":( ";
}
function shock() {
document.getElementsByTagName('textarea')[0].innerHTML+= ":O ";
}
function smart() {
document.getElementsByTagName('textarea')[0].innerHTML+= ":Z ";
}
function tongue() {
document.getElementsByTagName('textarea')[0].innerHTML+= ":P ";
}
function wink() {
document.getElementsByTagName('textarea')[0].innerHTML+= ";) ";
}
</script>
<?php
echo "</head>";
echo "<body style='margin: 0pt;'>";
echo "<center><table>";
echo "<tr><td background='greengrad.gif'><div align=center><font class=text2>MessageBox</font></td></tr>";
echo "<tr><td>";
echo "<div align=center><a href=javascript:add('[b]TEXT[/b]')>";
echo "<IMG SRC='http://proboards8.com/boardimages/bold.gif' BORDER=0 ALT='Bold'></a>";
echo "<a href=javascript:add('[i]TEXT[/i]')>";
echo "<IMG SRC='http://proboards8.com/boardimages/italicize.gif' BORDER=0 ALT='Italicize'></a>";
echo "<a href=javascript:add('[u]TEXT[/u]')>";
echo "<IMG SRC='http://proboards8.com/boardimages/underline.gif' BORDER=0 ALT='Underline'></a>";
echo "<a href=javascript:add('[s]TEXT[/s]')>";
echo "<IMG SRC='http://proboards8.com/boardimages/strike.gif' BORDER=0 ALT='Strikethrough'></a>";
echo "<a href=javascript:add('[glow=red,2,300]TEXT[/glow]')>";
echo "<IMG SRC='http://proboards8.com/boardimages/glow.gif' BORDER=0 ALT='Glow'></a>";
echo "<a href=javascript:add('[shadow=red,left,300]TEXT[/shadow]')>";
echo "<IMG SRC='http://proboards8.com/boardimages/shadow.gif' BORDER=0 ALT='Shadow'></a>";
echo "<a href=javascript:add('[move]TEXT[/move]')>";
echo "<IMG SRC='http://proboards8.com/boardimages/move.gif' BORDER=0 ALT='Marquee'></a>";
echo "<a href=javascript:add('[left]TEXT[/left]')>";
echo "<IMG SRC='http://proboards8.com/boardimages/left.gif' BORDER=0 ALT='Align Left'></a>";
echo "<a href=javascript:add('[center]TEXT[/center]')>";
echo "<IMG SRC='http://proboards8.com/boardimages/center.gif' BORDER=0 ALT='Align Center'></a>";
echo "<a href=javascript:add('[right]TEXT[/right]')>";
echo "<IMG SRC='http://proboards8.com/boardimages/right.gif' BORDER=0 ALT='Align Right'></a>";
echo "<a href=javascript:add('[hr]')>";
echo "<IMG SRC='http://proboards8.com/boardimages/hr.gif' BORDER=0 ALT='Horizontal Rule'></a>";
echo "<a href=javascript:add('[size=2]TEXT[/size]')>";
echo "<IMG SRC='http://proboards8.com/boardimages/size.gif' BORDER=0 ALT='Font Size'></a>";
echo "<a href=javascript:add('[font=Verdana]TEXT[/font]')>";
echo "<IMG SRC='http://proboards8.com/boardimages/face.gif' BORDER=0 ALT='Font Face'></a>";
echo "</td></tr><tr><td><div align=center>";
echo "<a href=javascript:add('')>";
echo "<IMG SRC='http://proboards8.com/boardimages/url.gif' BORDER=0 ALT='Insert Hyperlink'></a>";
echo "<a href=javascript:add('[ftp][/ftp]')>";
echo "<IMG SRC='http://proboards8.com/boardimages/ftp.gif' BORDER=0 ALT='Insert Ftp Link'></a>";
echo "<a href=javascript:add('[img]URL[/img]')>";
echo "<IMG SRC='http://proboards8.com/boardimages/img.gif' BORDER=0 ALT='Insert Image'></a>";
echo "<a href=javascript:add('[email][/email]')>";
echo "<IMG SRC='http://proboards8.com/boardimages/email2.gif' BORDER=0 ALT='Insert Email'></a>";
echo "<a href=javascript:add('[table][tr][td][/td][/tr][/table]')>";
echo "<IMG SRC='http://proboards8.com/boardimages/table.gif' BORDER=0 ALT='Insert Table'></a>";
echo "<a href=javascript:add('[tr][/tr]')>";
echo "<IMG SRC='http://proboards8.com/boardimages/tr.gif' BORDER=0 ALT='Insert Table Column'></a>";
echo "<a href=javascript:add('[td][/td]')>";
echo "<IMG SRC='http://proboards8.com/boardimages/td.gif' BORDER=0 ALT='Insert Table Row'></a>";
echo "<a href=javascript:add('[sup][/sup]')>";
echo "<IMG SRC='http://proboards8.com/boardimages/sup.gif' BORDER=0 ALT='Superscript'></a>";
echo "<a href=javascript:add('[sub][/sub]')>";
echo "<IMG SRC='http://proboards8.com/boardimages/sub.gif' BORDER=0 ALT='Subscript'></a>";
echo "<a href=javascript:add('[tt][/tt]')>";
echo "<IMG SRC='http://proboards8.com/boardimages/tele.gif' BORDER=0 ALT='Teletype'></a>";
echo "<a href=javascript:add('
')>";[/quote]')>";
[code=php]
<script>
function add(text){
if(text.match(/[/i)&&(document.selection.createRange().text||window.getSelection())){
var begin=text.split(/]/i)[0]+"]"
var end=begin.replace(/[/i,"[/")
var selection=(document.selection)?document.selection.createRange().text:window.getSelection()
postmsg=document.postmodify.message
if(begin==""){postmsg.value=postmsg.value.replace(selection,"[url="+selection+"]LINK TEXT")}
else{postmsg.value=postmsg.value.replace(selection,begin+selection+end)}
}
else{ // this part is the Proboards code, not mine
if (document.postmodify.message.createTextRange && document.postmodify.message.caretPos) {
var caretPos = document.postmodify.message.caretPos;
caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ?
text + ' ' : text;
}
else {
document.postmodify.message.value += text;
}
document.postmodify.message.focus(caretPos)
}
}
</script>
[/code]
[code=php]
echo "sometext"textbetween quotes"sommoretext";
[/code]
[code=php]
echo "sometext"textbetween quotes"sommoretext";
[/code]
0.1.9 — BETA 5.18