0

Hello everybody.
I've tried the following code in the head:

<script language="JavaScript">
var TxtArea = 0;
function insert_bui( t ){
        if( !TxtArea        ) return;
        tx = document.selection.createRange( );
        switch( t ){
        case "B":
                tx.text = "-b-" + tx.text + "-/b-" ;
                break;
        case "I":
                tx.text = "-i-" + tx.text + "-/i-";
                break;
        case "U":
                tx.text = "-u-" + tx.text + "-/u-";
                break;
        }
        document.selection.empty( );
        TxtArea = 0;
}
</script>

And I put the following code in the body:

<form name="TFrm" action="Send.php">
<input type="button" value="B" onclick="TFrm.TxtA.focus(); insert_bui('B');">
<input type="button" value="I" onclick="TFrm.TxtA.focus(); insert_bui('I');">
<input type="button" value="U" onclick="TFrm.TxtA.focus(); insert_bui('U');">
<input type="text" name="TxtA">
<input type="submit" value="Submit">
</form>

This code should enclose the selected characters in the TxtA field with the tags I specified in the function.
However, when I click on any button, it adds nothing!
Any help would be appreciated.

2
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by Hani1991
1

I think this code is well-written and has no errors.. What's the browser you're running your code on?

Votes + Comments
I agree :(
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.