Ask Experts Questions for FREE Help !
Ask
    benn11's Avatar
    benn11 Posts: 1,036, Reputation: 43
    Ultra Member
     
    #1

    Jan 2, 2008, 05:01 AM
    Textarea cursor position
    I have a textarea in an asp page and I have an attribute to insert * symbol in the textarea upon a click in the textarea. Using "<textarea name="text" onfocus="if(this.value=='') this.value='*';">"

    The problem is that the cursor returns to the start position but I want the cursor to remain in the position after the * symbol is automatically inserted. How can this be done?
    jstrike's Avatar
    jstrike Posts: 418, Reputation: 44
    Full Member
     
    #2

    Jan 16, 2008, 09:20 AM
    This should work:

    Code:
    <textarea name="myTextArea" onClick="placeText(this,'*')"></textArea>
    		
    <script>
      function placeText(txtArea, txt) {
        if(txtArea.value!="") return;
    
        txtArea.value=txt;
        //FF will automatically put the cursor at the end so skip this IE specific part...
        if(navigator.userAgent.toLowerCase().indexOf("msie") != -1) {
          var range = txtArea.createTextRange();
          range.moveStart('character', 1);   
          range.select();  
        }
      }
    </script>

Not your question? Ask your question View similar questions

 

Question Tools Search this Question
Search this Question:

Advanced Search

Add your answer here.


Check out some similar questions!

Flashing cursor [ 1 Answers ]

When I turn on my computer I only get a flashing cursor. How can I fix it?

Cursor trouble [ 1 Answers ]

I have a mouse (Logitech Trackman Marble FX) that frequently becomes either frozen, or moves on its own accord- often drifting into a corner and stays there. Re-booting sometimes helps. Any idea what the cause/fix might be?

Computer Cursor [ 2 Answers ]

Is there a way to lock and unlock a arrow cursor? I like to spin gambling wheels. I have a extension Cable on my cursor cable so I can sit on my couch and spin the wheels.

Blink cursor [ 5 Answers ]

At boot up I get a blinking cursor on the top left on the monitor, I try to press f8 but can't get in to it, I can get into setup. Can someone help? Thanks Passaic33


View more questions Search