Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    Dec 2004
    Posts
    86
    Thanks
    17
    Thanked 2 Times in 2 Posts

    Question Getting undo and redo to work on a simple script

    Hi, i have a script that inserts text into a box when you press different buttons. It has undo and redo buttons, but how the hell do i get them working? I have used the following code to insert these 2 new functions and changed the onclick values to doUndo and do Redo etc.. but for some reason it wont work. If you right click in on the main text field you can do undo and redo, why not through these buttons?
    function doUndo()
    {
    iView.document.execCommand('undo', false, null);
    }

    function doRedo()
    {
    iView.document.execCommand('redo', false, null);
    }

    Code:
    <html>
    <head>
    
    
    
    <style>
    .MyBut { font-Size:14px;width:56px;background-color:red; }
    .MyBut2 { font-Size:14px;width:57px;background-color:blue; }
    .MyBut3 { font-Size:14px;width:56px;background-color:green; }
    .MyBut4 { font-Size:14px;width:56px;background-color:gold; }
    .MyBut5 { font-Size:14px;width:56px;background-color:purple; }
    .MyBut6 { font-Size:14px;width:56px;background-color:turquoise; }
    .MyBut7 { font-Size:14px;width:77px;background-color:grey; }
    .MyBut8 { font-Size:14px;width:45px;background-color:grey; }
    .MyBut9 { font-Size:14px;width:140px;background-color:grey; }
    .MyBut10 { font-Size:14px;width:32px;background-color:grey; }
    .MyBut11 { font-Size:14px;width:64px;background-color:grey; }
    .MyBut12 { font-Size:14px;width:68px;background-color:grey; }
    .MyBut13 { font-Size:14px;width:55px;background-color:grey; }
    .MyBut14 { font-Size:14px;width:191px;background-color:grey; }
    
    </style>
    
    <script type="text/javascript">
    
    var pos;
    var txtS='';
    var txtF='';
    
    function add(st){
     document.getElementById('TextAreaName').value+=st;
    }
    
    function checkCursor(where){
     largeArea=where;
     txtS='';txtF='';
     if (document.selection){
      largeArea.focus();
      sel=document.selection.createRange();
      if(sel.text==""){
       sel.text='µµµ';
       dummy=largeArea.createTextRange();
       dummy.findText('µµµ');
       dummy.select();
       pos=largeArea.value.indexOf('µµµ');
       document.selection.clear();
       largeArea.focus();
      }
     }
     else if (largeArea.selectionStart||largeArea.selectionStart == '0') {//Moz
      pos = largeArea.selectionStart;
     }
     txtS=largeArea.value.substring(0,pos);
     txtF=largeArea.value.substring(pos,largeArea.value.length);
    }
    
    function cmdA(el) {
     with(el){
      focus(); select();
     }
     if(document.all){
      window.status='Selected and Copied to Clipboard!';
      document.getElementById('CopyBut').value='Copied!';
      window.clipboardData.setData('Text',document.getElementById('TextAreaName').value);
      setTimeout('document.getElementById(\'CopyBut\');window.status=""',6000);
     }
     else {
      window.status='Press Ctrl & C to Copy the Text to the Clipboard';
      setTimeout('window.status=""',6000);
     }
    }
    
    
    function insert(){
      document.getElementById('TextAreaName').value=txtS+document.getElementById('jumpnumber').value+txtF;
      textS=document.getElementById('TextAreaName').value;
      textF='';
     }
    
    function clearDefault(){
     document.getElementById('TextAreaName').value='';
     textS=''; textF='';
    
    }
    
    function countit(){
     document.getElementById('displaycount').value = document.getElementById('TextAreaName').value.length+' ';
    }
    
    </script>
    </HEAD>
    
    <BODY>
    
    
    
    <form action="" name="FormName" method="post">
    <TEXTAREA id="TextAreaName" NAME="TextareaName" COLS="53" ROWS="5" onclick="javascript:checkCursor(this);" onmouseup="javascript:checkCursor(this);" >
    </TEXTAREA>
    <br>
    <input id="jumpnumber" NAME="jumpnumber" size="10">
    
    <input class="MyBut2" type="button" width="120" NAME="copyButton" value="  " onClick="add('€b')">
    <input class="MyBut" type="button" width="120" NAME="copyButton" value=" " onClick="add('€r')">
    <input class="MyBut3" type="button" width="120" NAME="copyButton" value="" onClick="add('€g')">
    <input class="MyBut4" type="button" width="120" NAME="copyButton" value="  " onClick="add('€y')">
    <input class="MyBut5" type="button" width="120" NAME="copyButton" value="" onClick="add('€m')">
    <input class="MyBut6" type="button" width="120" NAME="copyButton" value="" onClick="add('€c')">
    <input type="button" width="120" NAME="copyButton" value=" INSERT " onClick="insert();" >
        
    <input type="button" width="120" NAME="copyButton" value=" !! " onClick="add('!!')">
    <input type="button" width="120" NAME="copyButton" value=" !!!" onClick="add('!!!')">
    <input type="button" width="120" NAME="copyButton" value="!!!!" onClick="add('!!!!')">
    <input type="button" width="120" NAME="copyButton" value=" .:: " onClick="add('.::')">
    <input type="button" width="120" NAME="copyButton" value=" ::. " onClick="add('::.')">
    <input type="button" width="120" NAME="copyButton" value=">>> " onClick="add('>>>')">
    <input type="button" width="120" NAME="copyButton" value=" <<<" onClick="add('<<<')">
    <input type="button" width="120" NAME="copyButton" value=" [[ " onClick="add('[[')">
    <input type="button" width="120" NAME="copyButton" value=" ]] " onClick="add(']]')">
    <input type="button" width="120" NAME="copyButton" value=" (( " onClick="add('((')">
    <input type="button" width="120" NAME="copyButton" value=" )) " onClick="add('))')">
    <input type="button" width="120" NAME="copyButton" value=" // " onClick="add('//')">
    <input type="button" width="120" NAME="copyButton" value=" \\ " onClick="add('\\')">
    <input type="button" width="120" NAME="copyButton" value=" { " onClick="add('{')">
    <input type="button" width="120" NAME="copyButton" value=" } " onClick="add('}')">
    <input type="button" width="120" NAME="copyButton" value="{{" onClick="add('{{')">
    <input type="button" width="120" NAME="copyButton" value="}}" onClick="add('}}')">
    <input type="button" width="120" NAME="copyButton" value="-=::" onClick="add('-=::')">
    <input type="button" width="120" NAME="copyButton" value="::=-" onClick="add('::=-')">
    <input type="button" width="120" NAME="copyButton" value="+//=" onClick="add('+//=')">
    <input type="button" width="120" NAME="copyButton" value="=\\+" onClick="add('=\\+')">
    <input type="button" width="120" NAME="copyButton" value="--==<<" onClick="add('--==<<')">
    <input type="button" width="120" NAME="copyButton" value=">>==--" onClick="add('>>==--')">
    <input type="button" width="120" NAME="copyButton" value="<--+-->" onClick="add('<--+-->')">
    <input type="button" width="120" NAME="copyButton" value="{}" onClick="add('{}')">
    <input type="button" width="120" NAME="copyButton" value=" .::. " onClick="add('.::.')">
    <input type="button" width="120" NAME="copyButton" value="  ^^ " onClick="add('^^')">
    <input type="button" width="120" NAME="copyButton" value="<<>>" onClick="add('<<>>')">
    <input class="MyBut10" type="button" width="120" NAME="copyButton" value=" <> " onClick="add('<>')">
    <input type="button" width="120" NAME="copyButton" value="--=--=--" onClick="add('--=--=--')">
    <input type="button" width="120" NAME="copyButton" value="--=--" onClick="add('--=--')">
    <input type="button" width="120" NAME="copyButton" value="<~~~>" onClick="add('<~~~>')">
    <input type="button" width="120" NAME="copyButton" value="Join@Jpool.co.uk" onClick="add('Join@Jpool.co.uk')">
    <input type="button" width="120" NAME="copyButton" value="www.Jpool.co.uk" onClick="add('www.Jpool.co.uk')">
    <input type="button" width="120" NAME="copyButton" value="  4 man  " onClick="add('4 man')">
    <input class="MyBut11" type="button" width="120" NAME="copyButton" value=" 8 man " onClick="add('8 man')">
    <input type="button" width="120" NAME="copyButton" value=" 16 man " onClick="add('16 man')">
    <input type="button" width="120" NAME="copyButton" value=" 32 man " onClick="add('32 man')">
    <input type="button" width="120" NAME="copyButton" value="64 man" onClick="add('64 man')">
    <input type="button" width="120" NAME="copyButton" value="  SE  " onClick="add(' SE')">
    <input type="button" width="120" NAME="copyButton" value=" DE " onClick="add(' DE')">
    <input class="MyBut12" type="button" width="120" NAME="copyButton" value="  1 vs 1  " onClick="add(' 1 vs 1')">
    <input type="button" width="120" NAME="copyButton" value="2 vs 2" onClick="add(' 2 vs 2')">
    <input type="button" width="120" NAME="copyButton" value="3 vs 3" onClick="add(' 3 vs 3')">
    <input type="button" width="120" NAME="copyButton" value="4 vs 4" onClick="add(' 4 vs 4')">
    <input type="button" width="120" NAME="copyButton" value="5 vs 5" onClick="add(' 5 vs 5')">
    <input type="button" width="120" NAME="copyButton" value="6 v 6" onClick="add(' 6 vs 6')">
    <input type="button" width="120" NAME="copyButton" value="3 Rd" onClick="add(' 3 Round')">
    <input type="button" width="120" NAME="copyButton" value="4 Rd" onClick="add(' 4 Round')">
    <input type="button" width="120" NAME="copyButton" value="5 Rd" onClick="add(' 5 Round')">
    <input type="button" width="120" NAME="copyButton" value="6 Rd" onClick="add(' 6 Round')">
    <input type="button" width="120" NAME="copyButton" value="7 Rd" onClick="add(' 7 Round')">
    <input type="button" width="120" NAME="copyButton" value="8 Rd" onClick="add(' 8 Round')">
    <input class="MyBut8" type="button" width="120" NAME="copyButton" value="Swiss" onClick="add(' Swiss')">
    <input class="MyBut7" type="button" width="120" NAME="copyButton" value="True Swiss" onClick="add(' True Swiss')">
    <input class="MyBut9" type="button" value="Calculate Characters" 
          onClick="countit(this)"> 
    <input type="text" VALUE="Max 200" name="displaycount" size="5">
    <input type="button" width="120" NAME="copyButton" value=" Clear " onClick="clearDefault(TextareaName)">
    <input type="button" width="120" NAME="copyButton" value=" Undo " onClick="clearDefault(TextareaName)">
    <input type="button" width="120" NAME="copyButton" value=" Redo " onClick="clearDefault(TextareaName)"> 
    <input class="MyBut13" type="button" width="120" NAME="copyButton" value="Save.." onClick="clearDefault(TextareaName)"> 
    <center>
    <input class=''MyBut14'' type="button" id="CopyBut" value="COPY TEXT" onClick="cmdA(TextareaName)">
    
    
    
    
          </p>
          <div align="center"><center><p><font face="comic sans ms" size="-2">
    </form>
    </body>
    </html>

  • #2
    Regular Coder
    Join Date
    Aug 2004
    Location
    codegoboom@yahoo.com
    Posts
    999
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Undo/Redo works on the last applied execCommand.
    *this message will self destruct in n-seconds*

  • #3
    New Coder
    Join Date
    Dec 2004
    Posts
    86
    Thanks
    17
    Thanked 2 Times in 2 Posts
    what is a execCommand?
    I put those 2 functions in, and made the buttons launch them onclick.
    could i have missed something small out?

  • #4
    Regular Coder
    Join Date
    Aug 2004
    Location
    codegoboom@yahoo.com
    Posts
    999
    Thanks
    0
    Thanked 0 Times in 0 Posts
    execCommand is a method of the Internet Explorer scriptable editing API.
    You appear to have missed calling execCommand, all together...
    *this message will self destruct in n-seconds*

  • #5
    New Coder
    Join Date
    Dec 2004
    Posts
    86
    Thanks
    17
    Thanked 2 Times in 2 Posts
    many thanks i have it working properly now


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •