#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Posts
    24
    Rep Power
    0

    Subsctipt and superscript


    Hi,
    I want to do the button for subscript and superscript. For example now, when we r typing the question in this textarea, if we want to highlight the main text we r selecting the statement and we click the B for bold. Then our statement becomes like <b>.....</b> Like this i want to do for subscript and superscript. If i give X2 I want to do like X<sub>2</sub>. Please tell me how to do this.
  2. #2
  3. No Profile Picture
    Lost in code
    Devshed Supreme Being (6500+ posts)

    Join Date
    Dec 2004
    Posts
    8,317
    Rep Power
    7170
    Search for a WYSIWYG editor. There are a variety of JavaScript based editors that will do that for you. Building one yourself is very complicated.
    PHP FAQ

    Originally Posted by Spad
    Ah USB, the only rectangular connector where you have to make 3 attempts before you get it the right way around
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Posts
    24
    Rep Power
    0
    Code:
    <button type="button" onclick="addtext();getfocus();">Subscript</button>
    
    function addtext() {
    var newtext = document.getElementById("ques1").value;
    newtext += prompt("enter the value",'<sub></sub>');
    document.getElementById("ques1").value = newtext;
    document.getElementById('ques1').focus();
    }
    The above is my code. I did it for one textarea. But if i'm having another textarea and i want to include the subscript in that textarea only, How can i do this.Please tell me.

IMN logo majestic logo threadwatch logo seochat tools logo