Textarea med link og smilley
Jeg har lavet et forum, hvor nye indlæg skrives i et textarea. Deri vil jeg gerne gøre det muligt for brugeren at taste et link eller indsætte smileys, men det virker kun hvis brugeren markerer teksten hvor han vil sætte link eller smiley ind bagefter, og det er jo ikke særlig hensigtsmæssigt.Er der mon nogen der kan se fejlen i min kode:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<!--#include file="functions.inc"-->
<%
Set myConn = Server.CreateObject("ADODB.Connection")
myConn.Open strDSN
Posted = 0
subjectnew= ""
if request.querystring("messageid") <> "" then
strSQL = "SELECT * from TEntries WHERE id=" & request.Querystring("Messageid")
set messagearr=myConn.Execute(strSQL)
subjectnew=messagearr("Subject")
end if
If Len(Trim(Request.Form("Subject"))) = 0 AND Len(Trim(Request.Form("Comment"))) = 0 Then
strSQL = "SELECT * FROM TForums WHERE (ID = " & Request("ForumID") & ")"
Set rs = myConn.Execute(strSQL)
If Not (rs.BOF Or rs.EOF) Then
intForumID = rs("ID")
strForum = rs("Forum")
End If
Else
strSQL = "INSERT INTO TEntries"
If Len(Trim(Request.Form("MessageId"))) = 0 Then
strSQL = strSQL & " (Name, Email, Subject, Comment, ForumId, Orgthread)"
strSQL = strSQL & " VALUES('" & DBFix(Trim(Request.Form("Name"))) & "', '" & DBFix(Trim(Request.Form("Email"))) & "', '" & DBFix(Trim(Request.Form("Subject"))) & "', '" & DBFix(Trim(Request.Form("Comment"))) & "', '" & DBFix(Trim(Request("ForumId"))) & "', TRUE);"
Else
tempSQL = "SELECT Subject FROM TEntries WHERE (Id = " & Request("MessageId") & ")"
Set tempRS = myConn.Execute(tempSQL)
strSQL = strSQL & " (Name, Email, Comment, ForumId, ReplyId, Subject)"
strSQL = strSQL & " VALUES('" & DBFix(Trim(Request.Form("Name"))) & "', '" & DBFix(Trim(Request.Form("Email"))) & "', '" & DBFix(Trim(Request.Form("Comment"))) & "', '" & DBFix(Trim(Request("ForumId"))) & "','" & DBFix(Trim(Request("MessageId"))) & "','" & DBFix(Trim(tempRS("Subject"))) & "' );"
tempRS.Close
End If
response.write(strSQL)
myConn.Execute(strSQL)
Posted = 1
End If
%>
<html>
<head>
</head>
<body bgcolor="#999966">
<table width="87%" cellpading="3">
<tr><td align="left">
<tr>
<td><font face="Verdana" size="2"><b>:: <%=strForum%></b></td>
</tr>
<tr><td><font face="Verdana" size="2"><hr color="#000000"></td> </tr>
<tr><td width="90%">
<table width="338"><tr><td width="40"> </td>
<td width="103"><font face="Verdana" size="2"><INPUT type="button" value="U" onclick="Underline()" style="margin:7px 1px; text-decoration: underline"></td>
<td width="43"><font face="Verdana" size="2"><INPUT type="button" value="F" onclick="Bold()" style="margin:7px 1px; font-weight: bold"></td>
<td width="56"><font face="Verdana" size="2"><INPUT type="button" value="K" onclick="Italic()" style="margin:7px 1px; font-style: italic"></td>
<td width="56"><font face="Verdana" size="2"><INPUT type="button" value="Link" onclick="Link()" style="color: blue; text-decoration: underline"></td>
<td width="50">
<table border="0" cellpadding="5" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="426" id="table2">
<tr>
<td width="26" align="center"> <a href="#" onclick="insertImg('<img src=Billeder/Smileys/023.gif border=0>')"><img src="Billeder/Smileys/023.gif" border="0"></a></td>
</tr>
</table>
</td>
</tr></table>
</td></tr>
<tr>
<td >
<%If Len(Trim(Request.Form("Subject"))) = 0 AND Len(Trim(Request.Form("Comment"))) = 0 Then%>
<form method="POST" action="forumpost.asp?ID="<% =Request("ForumID")%>>
<input type="hidden" name="name" value="<% =session("brugernavn")%>">
<input type="hidden" name="ForumID" value="<%=intForumID%>">
<input type="hidden" name="MessageID" value="<%=Trim(Request("MessageID"))%>">
<table border="0" width="45%" cellspacing="0" cellpadding="0">
<tr>
<td align="left"><font face="Verdana" size="1"><b>Emne</b></font></td>
<td align="left" width="358">
<input type="text" name="Subject" size="50" value="<%=Subjectnew%>" ></td>
</tr>
<tr>
<td valign="top" align="left"><font face="Verdana" size="1"><b>Indlæg</b></font></td>
<td align="left" width="358"><TEXTAREA name="Comment" cols=38 rows=5 wrap="virtual"></TEXTAREA></td>
</tr>
</table>
</td>
</tr>
<tr>
<td align="center">
<table border="0" style="border-collapse: collapse" width="100%" id="table1">
<tr>
<td width="35"> </td>
<td width="396">
<input type="submit" value="Opret indlæg" tabindex="3" name="Submit" id="submit1" style="margin:7px 1px; float:left"></td>
<td> </td>
</tr>
</table>
</td>
</tr>
<SCRIPT type="text/javascript">
<!--
var Underline_Active = false;
var Bold_Active = false;
var Italic_Active = false;
Comment = document.forms[0].Comment;
var Elements = document.getElementsByName("Subject");
Elements[0].focus();
function Underline()
{
var Selected = document.selection.createRange();
if (Selected.text.length > 0)
Selected.text = "<U>" + Selected.text + "</U>";
else
{
Selected.text = (Underline_Active) ? "</U>" : "<U>";
Underline_Active = !Underline_Active;
}
}
function Bold()
{
var Selected = document.selection.createRange();
if (Selected.text.length > 0)
Selected.text = "<B>" + Selected.text + "</B>";
else
{
Selected.text = (Bold_Active) ? "</B>" : "<B>";
Bold_Active = !Bold_Active;
}
}
function Italic()
{
var Selected = document.selection.createRange();
if (Selected.text.length > 0)
Selected.text = "<I>" + Selected.text + "</I>";
else
{
Selected.text = (Italic_Active) ? "</I>" : "<I>";
Italic_Active = !Italic_Active;
}
}
function Link()
{
var LinkURL = prompt("Indtast et link", "http://");
if (LinkURL == "http://" || LinkURL == null)
return;
var LinkTitle = prompt("Indtast navnet på linket", "");
document.selection.empty();
Comment.focus();
var Selected = document.selection.createRange();
if (LinkTitle == "" || LinkTitle == null)
Selected.text = Selected.text + "" + LinkURL + "";
else
Selected.text = Selected.text + "<a href='" + LinkURL + target='_blank'"'>" + " " + "<U><B>" + "LinkTitle" + "</U></B></a>";
}
function insertImg(imgUrl)
{
var Selected = document.selection.createRange();
if (Selected.text.length > 0)
Selected.text = Selected.text + " " + imgUrl;
}
//-->
</SCRIPT>
</table>
<%
Else
response.redirect("forumthreads.asp?forumID=" & request("forumID"))
End If
myConn.Close %>
</body>
</html>