Hello;
I got a BBcode from a website,and it is from http://www.iceteks.com/articles.php/javascript/2 but it does not work. Could anyone help me to find out the problem?

the problem i got are
1) some unexpected text display on the textarea.
2) when i click on the button, it does not work?


main.html
Code:
<html><head>
<title>Editor</title>
<script src="editor.js"></script>

<link rel="stylesheet" type="text/css" href="style.css" />


</head><body>
<form action="bbcode.php" method="post" name="editform" onsubmit="return checkForm(this)">
<table id="editform">
<tr>
        <td colspan="2" id="header">Post a new message</td>
</tr>

<tr id="subject">
        <td>Subject:</td>
        <td><input type="text" name="subject" size="50" class="form_elements_text"/></td>
</tr>
<tr>
        <td rowspan="2" id="smilies">Smilies
                <a href="javascript:smilie(':)')">
                        <img src="smilies/yellow/smile.gif" alt="smile" title="smile" /></a>
                <a href="javascript:smilie(':D')">
                        <img src="smilies/yellow/biggrin.gif" alt="big grin" title="big grin"/></a>
                <a href="javascript:smilie(':p')">
                        <img src="smilies/yellow/razz.gif" alt="razz" title="razz" /></a></td>
        <td>
                <input type="button" class="button" value="bold" name="bold" onclick="javascript:tag('b', '', 'bold*', '', 'bold', 'bold');" onMouseOver="helpline('bold')" />
                <input type="button" class="button" value="italic" name="italic" onclick="javascript:tag('i', '', 'italic*', '', 'italic', 'italic');" onMouseOver="helpline('italic')" />
                <input type="button" class="button" value="underline" name="underline" onclick="javascript:tag('u', '', 'underline*', '', 'underline', 'underline');" onMouseOver="helpline('underline')" />
                <input type="button" class="button" value="quote" name="quote" onclick="javascript:tag('q', '
', 'quote*', '
', 'quote', 'quote');" onMouseOver="helpline('quote')" /> <input type="button" class="button" value="code" name="code" onclick="javascript:tag('c', '
Code:
', 'code*', '
', 'code', 'code');" onMouseOver="helpline('code')" /> <input type="button" class="button" value="url" name="url" onclick="javascript:tag('url', '', 'url*', '', 'url', 'url');" onMouseOver="helpline('url')" /> <input type="button" class="button" value="img" name="img" onclick="javascript:tag('img', '[img]', 'img*', '[/img]', 'img', 'img');" onMouseOver="helpline('img')" /> <br /> Font size: <select name="fontsize" onChange="font('[size=' + this.form.fontsize.options[this.form.fontsize.selectedIndex].value + ']', '[/size]'); this.selectedIndex=2;" onMouseOver="helpline('fontsize')" class="form_elements_dropdown"> <option value="50%" >Tiny</option> <option value="75%" >Small</option> <option value="100%" selected >Normal</option> <option value="150%" >Large</option> <option value="200%" >Huge</option> </select> Font color: <select name="fontcolor" onChange="font('[color=' + this.form.fontcolor.options[this.form.fontcolor.selectedIndex].value + ']', '[/color]'); this.selectedIndex=0;" onMouseOver="helpline('fontcolor')" class="form_elements_dropdown" > <option value="black" style="color:black">Black</option> <option value="silver" style="color:silver">Silver</option> <option value="gray" style="color:gray">Gray</option> <option value="maroon" style="color:maroon">Maroon</option> <option value="red" style="color:red">Red</option> <option value="purple" style="color:purple">Purple</option> <option value="fuchsia" style="color:fuchsia">Fuchsia</option> <option value="navy" style="color:navy">Navy</option> <option value="blue" style="color:blue">Blue</option> <option value="aqua" style="color:aqua">Aqua</option> <option value="teal" style="color:teal">Teal</option> <option value="lime" style="color:lime">Lime</option> <option value="green" style="color:green">Green</option> <option value="olive" style="color:olive">Olive</option> <option value="yellow" style="color:yellow">Yellow</option> <option value="white" style="color:white">White</option> </select> <br /> <input type="text" name="helpbox" size="75" class="helpbox" readonly="readonly"/> </td> </tr> <tr> <td> Post:<br /> <textarea rows="10" cols="50" name="post" class="form_elements_text"><textarea> </td> </tr> <tr> <td colspan="2" id="post"> <input type="submit" name="Post" value="Post" class="button" /> <input type="submit" name="preview" value="Preview" class="button"/> <input type="reset" value="Start over" class="button" onclick="javascript:confirm_reset();"/> </td> </tr> </table> </form> </body></html>

Style.css

Code:
<style type="text/css">

/*Formatting for the buttons*/

.button {
        background-color : #D7D7D7;
        color : #000000;
        font-size: 11px; font-family: Verdana, Arial, Helvetica, sans-serif;
        margin-bottom:3px;
        margin-left:1px; margin-right:1px;
        margin-top:2px
}
/*Blends the helpbox into the background of the page*/
.helpbox {border-style:none;
                background-color:#CCC;
                margin:5px;
}

/*Sets the properties of the editform table cells*/
table#editform {border-width:1px;
                border-style:solid;
                background-color:#CCC;
                width:400px;
}

table#editform > tr,td {border-width:1px;
                border-style:solid;
}

td#header {border-style:none;
                text-align:center;
}

td#smilies {text-align:center;
                vertical-align:top;
                padding: 10px;
}

td#post {text-align:center;
}

/*Background color for the subject line and post area*/
.form_elements_text {background-color:#D7D7D7
}

/*Background color for the dropdown menus*/
.form_elements_dropdown {background-color:#D7D7D7
}

img {border-style:none}
</style>


editor.js

Code:

<script type="text/javascript">
//Variables for controlling opening and closing tags (function tag)

var b = 2;
var i = 2;
var u = 2;
var q = 2;
var c = 2;
var url = 2;
var img = 2;

//Function for creating non-font tags

function tag(v, tagadd, newbut, tagclose, oldbut, name) {
    if (eval(v)%2 == 0) {
        eval("window.document.editform."+name+".value = newbut;");
        var post = window.document.editform.post.value;
        window.document.editform.post.value = post + tagadd;
        window.document.editform.post.focus();
    } else {
        eval("window.document.editform."+name+".value = oldbut;");
        var post = window.document.editform.post.value;
        window.document.editform.post.value = post + tagclose;
        window.document.editform.post.focus();
    }
    eval(v+"++;");
}


if (eval(v)%2 == 0) {
eval("window.document.editform."+name+".value = newbut;");
        var post = window.document.editform.post.value;
        window.document.editform.post.value = post + tagadd;
        window.document.editform.post.focus();
eval(v+"++;");
} else {
        eval("window.document.editform."+name+".value = oldbut;");
        var post = window.document.editform.post.value;
        window.document.editform.post.value = post + tagclose;
        window.document.editform.post.focus();
    }
//Function for adding font color and size tags

function font(bbopen, bbclose) {
        var post = document.editform.post;
        post.value += bbopen + bbclose;
        post.focus();
        return;
}
//Function for adding smilies

function smilie (smilie) {
        var post = document.editform.post;
        post.value += smilie;
        post.focus();
        return;
}
//Helpbox messages
bold_help = "Bold text: text";
italic_help = "Italic text: text";
underline_help = "Underline text: text";
quote_help = "Quote text: 
text
or
Quote Originally Posted by name
text
"; code_help = "Code display:
Code:
code
"; img_help = "Insert image: "; url_help = "Insert URL: http://url or URL text"; fontcolor_help = "Font color: text Tip: you can also use color=#FF0000"; fontsize_help = "Font size: [size=50%]small text[/size]"; //Function for displaying help information // Shows the help messages in the helpline window function helpline(help) { var helpbox = document.editform.helpbox; helpbox.value = eval(help + "_help"); } //Function to confirm reset function confirm_reset () { if(confirm("If you continue you will loose everything you have entered so far. \n \n" + "Click OK to proceed and start again. \n \n Alternatively click cancel to continue " + "working on your post.")) { return true; } else { return false; } //Check the form submission for errors function checkForm() { var subject = document.editform.subject; var post = document.editform.post; //Check to make sure post lengths are sensible if (subject.value.length < 2 && post.value.length < 2) { alert("This is a short post!" + " \n \n " + "We require that each post (and subject) \n" + "be at least 2 characters long. \n \n" + "Go back and try again."); return false; } else { if (subject.value.length < 2) { alert("We require that the subject \n" + "be at least 2 characters long. \n \n" + "Go back and try again."); return false; } else { if (post.value.length < 2) { alert("We require that each post \n" + "be at least 2 characters long. \n \n" + "Go back and try again."); return false; } else { return true; } } } } </script>
[code]