0

Hi,

I have a few buttons to manipulate selected text in textarea but cannot work out how to do it. I mean I tried some examples on web but they are not really cross-browser compatible. If one work then another wont etc.

Can anyone help me modify what I have below?

Thanks in advance

    <script text="text/javascript">  
    function insertAtCursor(myField, request)
    {
        var selected_text = ..............;

        if (request == 'a')
        {
            var user_input = prompt('Please enter the link:', 'http://');
            var add = '<a href="' + user_input + '">' + selected_text + '</a>';
        }
        else
        {
            var add = '<' + request + '>' + selected_text + '</' + request + '>';
        }

        Update_selected_text_within_textarea_here = add;
    }
    </script>


    <form name="myform">

        <input type="button" value="link" onclick="insertAtCursor(document.myform.textarea_content, 'a');" /> 
        <input type="button" value="bold" onclick="insertAtCursor(document.myform.textarea_content, 'b');" /> 
        <input type="button" value="italic" onclick="insertAtCursor(document.myform.textarea_content, 'i');" /> 
        <input type="button" value="under" onclick="insertAtCursor(document.myform.textarea_content, 'u');" />

        <br />

        <textarea id="mytextarea" name="textarea_content"></textarea>

    </form>
2
Contributors
2
Replies
3
Views
5 Years
Discussion Span
Last Post by veledrom
This topic has been dead for over six months. 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.