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
    Mar 2007
    Posts
    11
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Array class project question?

    Good Morning,

    I'm working on this form for a class project. I am unfamiliar with creating var and arrays. I need to trim this down by creating var and arrays within the script. Can you help? I tried a few things I found online but nothing really speaks to what I am trying to achieve with regards to maintaining the function of the form. A few notes:
    • We only use IE
    • innerText is fine as it is part of the lesson



    All assiatance is much appreciated. I wish I could buy a coffe for everyone who has helped me on here



    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Untitled Document</title>
    
    <script type = "text/javascript">
    
    function ClipBoard() 
    {
    	
    	
    document.forms[0].holdtext.innerText = document.forms[0].copytext1.innerText + " " + document.forms[0].copytext2.innerText + " " + document.forms[0].copytext3.innerText +" " + document.forms[0].copytext4.innerText + " " + document.forms[0].copytext5.innerText + " " + document.forms[0].copytext6.innerText + " " + document.forms[0].copytext7.innerText + " " + document.forms[0].copytext8.innerText + " " + document.forms[0].copytext9.innerText ;
    
    Copied = document.forms[0].holdtext.createTextRange();
    <!----------------------------------------------------->
    document.forms[0].holdtext2.innerText  = document.forms[0].copytext10.innerText + " " + document.forms[0].copytext11.innerText + " " + document.forms[0].copytext12.innerText +" " + document.forms[0].copytext13.innerText + " " + document.forms[0].copytext14.innerText + " " + document.forms[0].copytext15.innerText + " " + document.forms[0].copytext16.innerText + " " + document.forms[0].copytext17.innerText + " " + document.forms[0].copytext18.innerText ;
    
    <!----------------------------------------------------->
    document.forms[0].holdtext3.innerText = document.forms[0].copytext19.innerText + " " + document.forms[0].copytext20.innerText + " " + document.forms[0].copytext21.innerText +" " + document.forms[0].copytext22.innerText + " " + document.forms[0].copytext23.innerText + " " + document.forms[0].copytext24.innerText + " " + document.forms[0].copytext25.innerText + " " + document.forms[0].copytext26.innerText + " " + document.forms[0].copytext27.innerText ;
    
    <!----------------------------------------------------->
    document.forms[0].holdtext4.innerText = document.forms[0].copytext28.innerText + " " + document.forms[0].copytext29.innerText + " " + document.forms[0].copytext30.innerText +" " + document.forms[0].copytext31.innerText + " " + document.forms[0].copytext32.innerText + " " + document.forms[0].copytext33.innerText + " " + document.forms[0].copytext34.innerText + " " + document.forms[0].copytext35.innerText + " " + document.forms[0].copytext36.innerText ;
    
    <!----------------------------------------------------->
    document.forms[0].holdtext5.innerText = document.forms[0].copytext37.innerText + " " + document.forms[0].copytext38.innerText + " " + document.forms[0].copytext39.innerText +" " + document.forms[0].copytext40.innerText + " " + document.forms[0].copytext41.innerText + " " + document.forms[0].copytext42.innerText + " " + document.forms[0].copytext43.innerText + " " + document.forms[0].copytext44.innerText + " " + document.forms[0].copytext45.innerText ;
    
    <!----------------------------------------------------->
    document.forms[0].holdtext6.innerText = document.forms[0].copytext46.innerText + " " + document.forms[0].copytext47.innerText + " " + document.forms[0].copytext48.innerText +" " + document.forms[0].copytext49.innerText + " " + document.forms[0].copytext50.innerText + " " + document.forms[0].copytext51.innerText + " " + document.forms[0].copytext52.innerText + " " + document.forms[0].copytext53.innerText + " " + document.forms[0].copytext54.innerText ;
    
    <!----------------------------------------------------->
    Copied.execCommand("RemoveFormat");
    Copied.execCommand("Copy");
    window.status="Contents copied to clipboard"
    setTimeout("window.status=''",2500)
    }
    
    </script> 
       <script type="text/javascript">
    function setName()
    {
        document.forms[0].MainTextArea.value = document.forms[0].holdtext.value + ' ' + document.forms[0].holdtext2.value + ', ' + document.forms[0].holdtext3.value + ' ' + document.forms[0].holdtext4.value + ', ' + document.forms[0].holdtext5.value + ', ' + document.forms[0].holdtext6.value;
    
    }
    </script>
    </head>
    
    <body >
    <table>
    <tr>
     <td width="55%" bgcolor="#FFFFFF" class="tLBL1l"><span id="PROC_CODE" name="PROC_CODE">test for proc code</span>
    		
           </td>
        </tr>
     
        </table>
    
    <form>
    
    <textarea id = "copytext1" onkeyup="setName()" rows = 5 cols = "20"></textarea>
    <textarea id = "copytext2" onkeyup="setName()" rows = 5 cols = "20"></textarea>
    <textarea id = "copytext3" onkeyup="setName()" rows = 5 cols = "20"></textarea>
    <textarea id = "copytext4" onkeyup="setName()" rows = 5 cols = "20"></textarea>
    <textarea id = "copytext5" onkeyup="setName()" rows = 5 cols = "20"></textarea>
    <textarea id = "copytext6" onkeyup="setName()" rows = 5 cols = "20"></textarea>
    <textarea id = "copytext7" onkeyup="setName()" rows = 5 cols = "20"></textarea>
    <textarea id = "copytext8" onkeyup="setName()" rows = 5 cols = "20"></textarea>
    <textarea id = "copytext9" onkeyup="setName()" rows = 5 cols = "20"></textarea>
    
    <textarea id="holdtext" style ="display:;"></textarea>
    <br><br>
    <!----------------------------------------------------------------->
    <textarea id = "copytext10" onkeyup="setName()" rows = 5 cols = "20"></textarea>
    <textarea id = "copytext11" onkeyup="setName()" rows = 5 cols = "20"></textarea>
    <textarea id = "copytext12" onkeyup="setName()" rows = 5 cols = "20"></textarea>
    <textarea id = "copytext13" onkeyup="setName()" rows = 5 cols = "20"></textarea>
    <textarea id = "copytext14" onkeyup="setName()" rows = 5 cols = "20"></textarea>
    <textarea id = "copytext15" onkeyup="setName()" rows = 5 cols = "20"></textarea>
    <textarea id = "copytext16" onkeyup="setName()" rows = 5 cols = "20"></textarea>
    <textarea id = "copytext17" onkeyup="setName()" rows = 5 cols = "20"></textarea>
    <textarea id = "copytext18" onkeyup="setName()" rows = 5 cols = "20"></textarea>
    <textarea id="holdtext2" style ="display:;"></textarea>
    <br><br>
    <!----------------------------------------------------------------->
    <textarea id = "copytext19" onkeyup="setName()" rows = 5 cols = "20"></textarea>
    <textarea id = "copytext20" onkeyup="setName()" rows = 5 cols = "20"></textarea>
    <textarea id = "copytext21" onkeyup="setName()" rows = 5 cols = "20"></textarea>
    <textarea id = "copytext22" onkeyup="setName()" rows = 5 cols = "20"></textarea>
    <textarea id = "copytext23" onkeyup="setName()" rows = 5 cols = "20"></textarea>
    <textarea id = "copytext24" onkeyup="setName()" rows = 5 cols = "20"></textarea>
    <textarea id = "copytext25" onkeyup="setName()" rows = 5 cols = "20"></textarea>
    <textarea id = "copytext26" onkeyup="setName()" rows = 5 cols = "20"></textarea>
    <textarea id = "copytext27" onkeyup="setName()" rows = 5 cols = "20"></textarea>
    
    <textarea id="holdtext3" style ="display:;"></textarea>
    <br><br>
    <!----------------------------------------------------------------->
    <textarea id = "copytext28" onkeyup="setName()" rows = 5 cols = "20"></textarea>
    <textarea id = "copytext29"  onkeyup="setName()" rows = 5 cols = "20"></textarea>
    <textarea id = "copytext30" onkeyup="setName()" rows = 5 cols = "20"></textarea>
    <textarea id = "copytext31" onkeyup="setName()" rows = 5 cols = "20"></textarea>
    <textarea id = "copytext32" onkeyup="setName()" rows = 5 cols = "20"></textarea>
    <textarea id = "copytext33" onkeyup="setName()" rows = 5 cols = "20"></textarea>
    <textarea id = "copytext34" onkeyup="setName()" rows = 5 cols = "20"></textarea>
    <textarea id = "copytext35" onkeyup="setName()" rows = 5 cols = "20"></textarea>
    <textarea id = "copytext36" onkeyup="setName()" rows = 5 cols = "20"></textarea>
    <textarea id="holdtext4" style ="display:;"></textarea>
    <br><br>
    <!----------------------------------------------------------------->
    <textarea id = "copytext37" onkeyup="setName()" rows = 5 cols = "20"></textarea>
    <textarea id = "copytext38" onkeyup="setName()" rows = 5 cols = "20"></textarea>
    <textarea id = "copytext39" onkeyup="setName()" rows = 5 cols = "20"></textarea>
    <textarea id = "copytext40" onkeyup="setName()" rows = 5 cols = "20"></textarea>
    <textarea id = "copytext41" onkeyup="setName()" rows = 5 cols = "20"></textarea>
    <textarea id = "copytext42" onkeyup="setName()" rows = 5 cols = "20"></textarea>
    <textarea id = "copytext43" onkeyup="setName()" rows = 5 cols = "20"></textarea>
    <textarea id = "copytext44" onkeyup="setName()" rows = 5 cols = "20"></textarea>
    <textarea id = "copytext45" onkeyup="setName()" rows = 5 cols = "20"></textarea>
    
    <textarea id="holdtext5" style ="display:;"></textarea>
    <br><br>
    <!----------------------------------------------------------------->
    <textarea id = "copytext46" onkeyup="setName()" rows = 5 cols = "20"></textarea>
    <textarea id = "copytext47" onkeyup="setName()" rows = 5 cols = "20"></textarea>
    <textarea id = "copytext48" onkeyup="setName()" rows = 5 cols = "20"></textarea>
    <textarea id = "copytext49" onkeyup="setName()" rows = 5 cols = "20"></textarea>
    <textarea id = "copytext50" onkeyup="setName()" rows = 5 cols = "20"></textarea>
    <textarea id = "copytext51" onkeyup="setName()" rows = 5 cols = "20"></textarea>
    <textarea id = "copytext52" onkeyup="setName()" rows = 5 cols = "20"></textarea>
    <textarea id = "copytext53" onkeyup="setName()" rows = 5 cols = "20"></textarea>
    <textarea id = "copytext54" onkeyup="setName()" rows = 5 cols = "20"></textarea>
    <textarea id="holdtext6" style ="display:;"></textarea>
    <br><br>
    <input type = "button" onClick="ClipBoard(),setName();" value = "Copy to Clipboard" /></button> 
    <tr>
      <td style="width: 421px"><br />
      Created this outcome:<br />
      <input name="MainTextArea"  style="width: 286px; height: 90px" type="text" wrap="hard" />
      <br />
      </td>
    </tr>
    <!----------------------------------------------------------------->
    <br><br>
    
    
    </form>
    
    </body>
    </html>

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,979
    Thanks
    79
    Thanked 4,429 Times in 4,394 Posts
    Don't understand why you would use any arrays for this.

    On the other hand, you could easily compress the heck out of the code.

    Code:
    function ClipBoard() 
    {
        var form = document.forms[0];
        var copyFrom = 0;
        for ( var copyTo = 1; copyTo <= 6; ++copyTo )
        {
            var txt = "";
            var copyFromBase = 9 * (copyTo - 1 );
            for ( var copyFrom = copyFromBase + 1; copyFrom <= copyFromBase + 9; ++copyFrom )
            {
                txt += " " + form["copyText" + copyFrom].innerText;
            }
       	form["holdText" + (copyTo > 1 ? copyTo : "" )].innerText = txt.substring(1);
        }
        var Copied = form.holdtext.createTextRange();
        Copied.execCommand("RemoveFormat");
        Copied.execCommand("Copy");
        window.status="Contents copied to clipboard"
        setTimeout("window.status=''",2500)
    }
    If you had named your "holdText" consistently--if the first one was "holdText1"--then that (copyTo > 1 ? copyTo : "" ) would not be needed.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #3
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,068
    Thanks
    0
    Thanked 256 Times in 252 Posts
    I wonder why non-standard IE-proprietary script is part of the lesson. They should teach modern and standard scripting.
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________

  • #4
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,979
    Thanks
    79
    Thanked 4,429 Times in 4,394 Posts
    But that's why they call them "lessons". Because you learn less'n less'n each time you get one.

    Clearly, if you want to learn *MORE* then you should take morons instead.

    <grin style="I could not help myself"/>
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #5
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,642
    Thanks
    0
    Thanked 649 Times in 639 Posts
    I wouldn't use code that antiquated with IE4+ - that approach is only required for Internet Explorer Three where no better way of referencing the form than using the form collection is available.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.


  •  

    Tags for this Thread

    Posting Permissions

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