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.

Recommended Answers

All 2 Replies

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

commented: I agree :( +3

I'm executing my code on Firefox..

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.