69 users online (0 members and 69 guests)  


  Results 1 to 3 of 3

Related

  1. PHP script running when page loads    Forum: PHP Forum
    Replies: 1
  2. Replies: 0
  3. Replies: 0
  4. Passing variables from HTML page to page    Forum: HTML Forum
    Replies: 1
  5. Replies: 2
  1. #1
    RageDNA's Avatar
    New User

    Status
    Offline
    Join Date
    Sep 2003
    Posts
    4

    Post Need help with duplicating a script on the same page

    Hello, I'm new here...

    I would like to ask for some help on duplicating this script so that I can have up to 10 or more copy boxes on one webpage.

    The script is a simple copy script but I'm not sure of to get it to copy from each different box on the same page. I put three boxes in the script below. Now I just need to get the scrip to copy the information from each box separately.

    Please help.

    Here is the script.


    <SCRIPT LANGUAGE="JavaScript">
    <!--

    var sp = window.location.hostname;

    function highlighttext() {
    document.cctext.text2copy.select(); document.cctext.text2copy.focus();
    }

    function copytext() {
    highlighttext();
    textRange = document.cctext.text2copy.createTextRange();
    textRange.execCommand("RemoveFormat");
    textRange.execCommand("Copy");
    }

    //-->
    </SCRIPT>


    <form name=cctext>

    <tr><td><p> </td></tr>

    <tr><td><table cellpadding=8 cellspacing=0 border=0 width=650 bgcolor=#DCDCDC><tr><td class=body><b>Conversion Counter</b></td></tr>
    <tr><td class=body>To get started, please add the following HTML code to the
    appropriate page on your Web site.<br><img src=/images/signup/clear.gif height=4 width=1 alt=""><br><table cellpadding=3 cellspacing=0 border=0>
    <tr><td colspan=2><textarea name=text2copy cols=50 rows=10 wrap=virtual readonly>Just Testing the copy box</textarea></td></tr>
    <tr valign=top><td class=small> </td><td align=right>
    <input type="button" value="Copy" onClick="copytext();"></td></tr>
    </table></td></tr>
    </table></td></tr></form>

    <form name=cctext>

    <tr><td><p> </td></tr>

    <tr><td><table cellpadding=8 cellspacing=0 border=0 width=650 bgcolor=#DCDCDC><tr><td class=body><b>Conversion Counter</b></td></tr>
    <tr><td class=body>To get started, please add the following HTML code to the
    appropriate page on your Web site.<br><img src=/images/signup/clear.gif height=4 width=1 alt=""><br><table cellpadding=3 cellspacing=0 border=0>
    <tr><td colspan=2><textarea name=text2copy cols=50 rows=10 wrap=virtual readonly>Just Testing the copy box</textarea></td></tr>
    <tr valign=top><td class=small> </td><td align=right>
    <input type="button" value="Copy" onClick="copytext();"></td></tr>
    </table></td></tr>
    </table></td></tr></form>

    <form name=cctext>

    <tr><td><p> </td></tr>

    <tr><td><table cellpadding=8 cellspacing=0 border=0 width=650 bgcolor=#DCDCDC><tr><td class=body><b>Conversion Counte</b></td></tr>
    <tr><td class=body>To get started, please add the following HTML code to the
    appropriate page on your Web site.<br><img src=/images/signup/clear.gif height=4 width=1 alt=""><br><table cellpadding=3 cellspacing=0 border=0>
    <tr><td colspan=2><textarea name=text2copy cols=50 rows=10 wrap=virtual readonly>Just Testing the copy box</textarea></td></tr>
    <tr valign=top><td class=small> </td><td align=right>
    <input type="button" value="Copy" onClick="copytext();"></td></tr>
    </table></td></tr>
    </table></td></tr></form>

  2. #2
    christodd's Avatar
    New User

    Status
    Offline
    Join Date
    Oct 2003
    Location
    Tacoma, Washington
    Posts
    20
    Quote Originally Posted by RageDNA
    Hello, I'm new here...
    Please help.

    Here is the script.

    <SCRIPT LANGUAGE="JavaScript">
    <!--

    var sp = window.location.hostname;

    function highlighttext() {
    document.cctext.text2copy.select(); document.cctext.text2copy.focus();
    }

    function copytext() {
    highlighttext();
    textRange = document.cctext.text2copy.createTextRange();
    textRange.execCommand("RemoveFormat");
    textRange.execCommand("Copy");
    }

    //-->
    </SCRIPT>

    <form name=cctext>
    <textarea name=text2copy cols=50 rows=10 wrap=virtual readonly>Just Testing the copy box</textarea>
    <input type="button" value="Copy" onClick="copytext();">
    RageDNA,
    Welcome to the forum.

    What you want is to change those functions to accept a parameter. I would even combine them into one. Also, you'll need to have different names for each form and input, those duplicate names will confuse the browser DOM table.

    Your script will look something like this :
    HTML Code:
    <SCRIPT LANGUAGE="JavaScript"> 
    <!-- 
    
    var sp = window.location.hostname; 
    
    function find_by_id(id) {
      if (!document.getElementById) {
     	return document.all[id]
     } else {
       return document.getElementById(id);
     }
    }
    
    function copytext(objId) {
    var obj=find_by_id(objId); 
    obj.select();
    obj.focus();
    textRange = obj.createTextRange(); 
    textRange.execCommand("RemoveFormat"); 
    textRange.execCommand("Copy"); 
    } 
    
    //--> 
    </SCRIPT> 
    
    <form name=cctext> 
    <textarea name=text2copy_a cols=50 rows=10 wrap=virtual readonly>Just Testing the copy box</textarea>
    <input type="button" value="Copy" onClick="copytext('text2copy_a');">
    </form>
    
    <form name=cctext2> 
    <textarea name=text2copy_b cols=50 rows=10 wrap=virtual readonly>Just Testing the copy box</textarea>
    <input type="button" value="Copy" onClick="copytext('text2copy_b');">
    </form>
    -Chris
    Last edited by HTML; 10-31-2003 at 04:56 PM.

  3. #3
    RageDNA's Avatar
    New User

    Status
    Offline
    Join Date
    Sep 2003
    Posts
    4
    I got it working...

    Cool thanks.

    RageDNA



Tags for this Thread