Problem with my guestbook
<p>Im trying to make a guestbook that allows smileys. I already made it parse things like <code>[smile]</code> etc and replace it with an image, but I cant get one thing to work.</p>

<p>When the user clicks on a smiley, I want it to insert the correct tag in the textbox, but it doesnt do anything. I used to javascript to try and insert the tags.</p>

<p>See link:</p>

<p><a href="http://www.vittoriosastarsnursery.com/guestsign.aspx" rel="nofollow">http://www.vittoriosastarsnursery.com/guestsign.aspx</a></p>

<p>Here is the code:</p>

<pre><code>&lt;%@ Page Explicit="True" Language="VB" Debug="True" ValidateRequest="false" %&gt;

&lt;%@ Register TagPrefix="aspHut" TagName="templateTop" Src="guesttop.ascx" %&gt;
&lt;%@ Register TagPrefix="aspHut" TagName="templateBottom" Src="guestbottom.ascx" %&gt;
&lt;%@ Import Namespace="System.Data" %&gt;
&lt;%@ Import Namespace="System.Data.OleDb" %&gt;
&lt;script runat="server"&gt;
    Dim strConnection As String = "provider=Microsoft.Jet.OLEDB.4.0;data source=" + Server.MapPath("guestbook.mdb.resources")

    Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    End Sub

    Sub btnSubmit_Click(ByVal sender As Object, ByVal e As EventArgs)
        If (Page.IsValid) Then
            ' using .Replace("'", "") to remove naughty single quote
            Dim sName As String = Server.HtmlEncode(txtName.Text.Replace("'", ""))
            Dim sEmail As String = Server.HtmlEncode(txtEmail.Text.Replace("'", ""))
            Dim sMessage As String = Server.HtmlEncode(txtMessage.Text.Replace("'", ""))

            Dim objConnection As OleDbConnection
            Dim objCmd As OleDbCommand
            Dim strSQL As String = "INSERT INTO messages (name, email, message) VALUES ('" &amp; sName &amp; "', '" &amp; sEmail &amp; "', '" &amp; sMessage &amp; "')"

            objConnection = New OleDbConnection(strConnection)
            objConnection.Open()

            objCmd = New OleDbCommand(strSQL, objConnection)
            objCmd.ExecuteNonQuery()

            objConnection.Close()
            Response.Redirect("Guestbook.aspx")
        Else
            Exit Sub
        End If
    End Sub
&lt;/script&gt;
&lt;aspHut:templateTop ID="UserControl1" runat="server"&gt;&lt;/aspHut:templateTop&gt;
&lt;script language="JavaScript"&gt;
    var bodytext = "";
    function AddText(NewCode) {
        var dob = document.formSign.txtMessage
        if (dob.createTextRange &amp;&amp; dob.caretPos) {
            var caretPos = dob.caretPos;
            caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? NewCode + ' ' : NewCode;
        }
        else if (dob.setSelectionRange) {
            dob.value = dob.value.substring(0, dob.selectionStart) + NewCode + dob.value.substring(dob.selectionEnd, dob.value.length);
        }
        else {
            dob.value += NewCode;
        }
        dob.focus();
        bodytext = "";
    }
&lt;/script&gt;
&lt;form id="formSign" runat="server"&gt;
&lt;p&gt;
    Please enter the following requested information below to sign the guestbook.
    &lt;table&gt;
        &lt;tr&gt;
            &lt;td align="left"&gt;
                &lt;b&gt;Your Name:&lt;/b&gt;&lt;asp:requiredfieldvalidator id="nameReqVal" runat="server" controltovalidate="txtName"
                    errormessage="Your Name."&gt;*&lt;/asp:requiredfieldvalidator&gt;
            &lt;/td&gt;
            &lt;td align="right"&gt;
                &lt;asp:textbox id="txtName" runat="server"&gt;&lt;/asp:textbox&gt;
            &lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
            &lt;td align="left"&gt;
                &lt;b&gt;Your Email Address:&lt;/b&gt;&lt;asp:regularexpressionvalidator id="emailRegEx" runat="server"
                    controltovalidate="txtEmail" errormessage="Your Email." validationexpression="\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"&gt;*&lt;/asp:regularexpressionvalidator&gt;
            &lt;/td&gt;
            &lt;td align="right"&gt;
                &lt;asp:textbox id="txtEmail" runat="server"&gt;&lt;/asp:textbox&gt;
            &lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr align="left"&gt;
            &lt;td colspan="3"&gt;
                &lt;b&gt;Your Message:&lt;/b&gt;&lt;asp:requiredfieldvalidator id="messageReqVal" runat="server"
                    controltovalidate="txtMessage" errormessage="Your Message."&gt;*&lt;/asp:requiredfieldvalidator&gt;
            &lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr align="left"&gt;
            &lt;td colspan="2"&gt;
                &lt;asp:textbox id="txtMessage" runat="server" textmode="MultiLine" columns="50" rows="10"&gt;&lt;/asp:textbox&gt;
            &lt;/td&gt;
            &lt;td&gt;
                &lt;table&gt;
                    &lt;tr&gt;
                        &lt;td&gt;
                            &lt;a href="javascript:void(AddText('[angel]'))"&gt;
                                &lt;img src="/Images/Smileys/angel_smile.gif" border="0" height="22" width="22" /&gt;&lt;/a&gt;
                        &lt;/td&gt;
                        &lt;td&gt;
                            &lt;a href="javascript:void(AddText('[angry]'))"&gt;
                                &lt;img src="/Images/Smileys/angry.gif" border="0" height="22" width="22" /&gt;&lt;/a&gt;
                        &lt;/td&gt;
                        &lt;td&gt;
                            &lt;a href="javascript:void(AddText('[teeth]'))"&gt;
                                &lt;img src="/Images/Smileys/baring_teeth.gif" border="0" height="22" width="22" /&gt;&lt;/a&gt;
                        &lt;/td&gt;
                        &lt;td&gt;
                            &lt;a href="javascript:void(AddText('[confused]'))"&gt;
                                &lt;img src="/Images/Smileys/confused.gif" border="0" height="22" width="22" /&gt;&lt;/a&gt;
                        &lt;/td&gt;
                    &lt;/tr&gt;
                    &lt;tr&gt;
                        &lt;td&gt;
                            &lt;a href="javascript:void(AddText('[cry]'))"&gt;
                                &lt;img src="/Images/Smileys/cry.gif" border="0" height="22" width="22" /&gt;&lt;/a&gt;
                        &lt;/td&gt;
                        &lt;td&gt;
                            &lt;a href="javascript:void(AddText('[dunno]'))"&gt;
                                &lt;img src="/Images/Smileys/dont_know.gif" border="0" height="22" width="22" /&gt;&lt;/a&gt;
                        &lt;/td&gt;
                        &lt;td&gt;
                            &lt;a href="javascript:void(AddText('[ssh]'))"&gt;
                                &lt;img src="/Images/Smileys/dont_tell.gif" border="0" height="22" width="22" /&gt;&lt;/a&gt;
                        &lt;/td&gt;
                        &lt;td&gt;
                            &lt;a href="javascript:void(AddText('[haha]'))"&gt;
                                &lt;img src="/Images/Smileys/hahaha.gif" border="0" height="22" width="22" /&gt;&lt;/a&gt;
                        &lt;/td&gt;
                    &lt;/tr&gt;
                    &lt;tr&gt;
                        &lt;td&gt;
                            &lt;a href="javascript:void(AddText('[nerd]'))"&gt;
                                &lt;img src="/Images/Smileys/nerd.gif" border="0" height="22" width="22" /&gt;&lt;/a&gt;
                        &lt;/td&gt;
                        &lt;td&gt;
                            &lt;a href="javascript:void(AddText('[omg]'))"&gt;
                                &lt;img src="/Images/Smileys/omg.gif" border="0" height="22" width="22" /&gt;&lt;/a&gt;
                        &lt;/td&gt;
                        &lt;td&gt;
                            &lt;a href="javascript:void(AddText('[party]'))"&gt;
                                &lt;img src="/Images/Smileys/party.gif" border="0" height="22" width="22" /&gt;&lt;/a&gt;
                        &lt;/td&gt;
                        &lt;td&gt;
                            &lt;a href="javascript:void(AddText('[red]'))"&gt;
                                &lt;img src="/Images/Smileys/red.gif" border="0" height="22" width="22" /&gt;&lt;/a&gt;
                        &lt;/td&gt;
                    &lt;/tr&gt;
                    &lt;tr&gt;
                        &lt;td&gt;
                            &lt;a href="javascript:void(AddText('[smile]'))"&gt;
                                &lt;img src="/Images/Smileys/regular_smile.gif" border="0" height="22" width="22" /&gt;&lt;/a&gt;
                        &lt;/td&gt;
                        &lt;td&gt;
                            &lt;a href="javascript:void(AddText('[rolleyes]'))"&gt;
                                &lt;img src="/Images/Smileys/roll.gif" border="0" height="22" width="22" /&gt;&lt;/a&gt;
                        &lt;/td&gt;
                        &lt;td&gt;
                            &lt;a href="javascript:void(AddText('[sad]'))"&gt;
                                &lt;img src="/Images/Smileys/sad_smile.gif" border="0" height="22" width="22" /&gt;&lt;/a&gt;
                        &lt;/td&gt;
                        &lt;td&gt;
                            &lt;a href="javascript:void(AddText('[wink]'))"&gt;
                                &lt;img src="/Images/Smileys/wink_smile.gif" border="0" height="22" width="22" /&gt;&lt;/a&gt;
                        &lt;/td&gt;
                    &lt;/tr&gt;
                    &lt;tr&gt;
                        &lt;td&gt;
                            &lt;a href="javascript:void(AddText('[sarcastic]'))"&gt;
                                &lt;img src="/Images/Smileys/sarcastic.gif" border="0" height="22" width="22" /&gt;&lt;/a&gt;
                        &lt;/td&gt;
                        &lt;td&gt;
                            &lt;a href="javascript:void(AddText('[shades]'))"&gt;
                                &lt;img src="/Images/Smileys/shades.gif" border="0" height="22" width="22" /&gt;&lt;/a&gt;
                        &lt;/td&gt;
                        &lt;td&gt;
                            &lt;a href="javascript:void(AddText('[what]'))"&gt;
                                &lt;img src="/Images/Smileys/what_smile.gif" border="0" height="22" width="22" /&gt;&lt;/a&gt;
                        &lt;/td&gt;
                        &lt;td&gt;
                            &lt;a href="javascript:void(AddText('[sick]'))"&gt;
                                &lt;img src="/Images/Smileys/sick.gif" border="0" height="22" width="22" /&gt;&lt;/a&gt;
                        &lt;/td&gt;
                    &lt;/tr&gt;
                    &lt;tr&gt;
                        &lt;td&gt;
                            &lt;a href="javascript:void(AddText('[sleepy]'))"&gt;
                                &lt;img src="/Images/Smileys/sleepy.gif" border="0" height="22" width="22" /&gt;&lt;/a&gt;
                        &lt;/td&gt;
                        &lt;td&gt;
                            &lt;a href="javascript:void(AddText('[grin]'))"&gt;
                                &lt;img src="/Images/Smileys/teeth_smile.gif" border="0" height="22" width="22" /&gt;&lt;/a&gt;
                        &lt;/td&gt;
                        &lt;td&gt;
                            &lt;a href="javascript:void(AddText('[thinking]'))"&gt;
                                &lt;img src="/Images/Smileys/thinking.gif" border="0" height="22" width="22" /&gt;&lt;/a&gt;
                        &lt;/td&gt;
                        &lt;td&gt;
                            &lt;a href="javascript:void(AddText('[tongue]'))"&gt;
                                &lt;img src="/Images/Smileys/tongue_smile.gif" border="0" height="22" width="22" /&gt;&lt;/a&gt;
                        &lt;/td&gt;
                    &lt;/tr&gt;
                &lt;/table&gt;
            &lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr align="left"&gt;
            &lt;td colspan="3"&gt;
                &lt;asp:validationsummary id="ValSum" runat="server" width="312px" headertext="Please correct the following error(s):"&gt;&lt;/asp:validationsummary&gt;
                &lt;asp:button id="btnSubmit" onclick="btnSubmit_Click" runat="server" text="Sign!"&gt;&lt;/asp:button&gt;
            &lt;/td&gt;
        &lt;/tr&gt;
    &lt;/table&gt;
&lt;/form&gt;
&lt;p align="center"&gt;
    &lt;a href="guestbook.aspx"&gt;View the guestbook&lt;/a&gt;&lt;/p&gt;
&lt;aspHut:templateBottom ID="UserControl2" runat="server"&gt;&lt;/aspHut:templateBottom&gt;
</code></pre>
