Snitz Forums 2000
Snitz Forums 2000
Home | Profile | Register | Active Topics | Members | Search | FAQ
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 Community Forums
 Community Discussions (All other subjects)
 Javascript select all script
 New Topic  Topic Locked
 Printer Friendly
Author Previous Topic Topic Next Topic  

Da_Stimulator
DEV Team Forum Moderator

USA
3373 Posts

Posted - 01 December 2004 :  22:24:17  Show Profile  Send Da_Stimulator an AOL message  Send Da_Stimulator a Yahoo! Message
Davio I remember you having something like this... to select all text within a div tag, but the script I found for that was if you click in the div.... is there a way to have a link to select all? I cant seem to get it working...

Chekc out the highlighted code

-Stim

Edited by - Da_Stimulator on 01 December 2004 22:34:33

Davio
Development Team Member

Jamaica
12217 Posts

Posted - 02 December 2004 :  00:44:26  Show Profile
This was the javascript function I went with Stim. I added the code in blue so it would copy the selection to IE's clipboard at the same time:
function copySel(tagID){
	refNode = document.getElementById(tagID);
	
	if (document.selection) {
		var range = document.body.createTextRange();
		range.moveToElementText(refNode);
		range.select();
		range.execCommand("Copy");
	} else if (window.getSelection) {
		var range = document.createRange();
		range.selectNodeContents(refNode);
		var selection = window.getSelection();
		selection.removeAllRanges();
		selection.addRange(range);
	}
}
And the button that called the script looked like this:
<input type="button" name="selectall" id="btn_selectall" value="Select All / Copy Text (IE Only)" onclick="copySel('funcsubs_desc')">
The 'tagID' is the id I gave the DIV.
<div id="funcsubs_desc" class="desc"></div>

Support Snitz Forums

Edited by - Davio on 02 December 2004 00:45:56
Go to Top of Page

Da_Stimulator
DEV Team Forum Moderator

USA
3373 Posts

Posted - 02 December 2004 :  01:21:12  Show Profile  Send Da_Stimulator an AOL message  Send Da_Stimulator a Yahoo! Message
sweet, thx davio, works like a charm :)

-Stim
Go to Top of Page

Da_Stimulator
DEV Team Forum Moderator

USA
3373 Posts

Posted - 04 December 2004 :  07:04:25  Show Profile  Send Da_Stimulator an AOL message  Send Da_Stimulator a Yahoo! Message
I posted on your forum davio, cross-posting here in case someone else can help out also...

What I want to do now is to make a button that selects highlighted lines only... I've tried over and over to learn how to do this with javascript, I've tried several methods; all to no avail. This is my latest concoction, but it does not work...

maybe someone can give me a helpful pointer. I've scrounged devguru and tried many things...

I'm not very javascript inclined (if you havnt noticed)


<html>
<head>

<script type="text/javascript">
divArray = new Array(1);
divArray[0] = "d1"
divArray[1] = "d3"

function separateIDs(fFake){
 for(i in divArray)
   copySel(divArray[i])
}
function copySel(tagID){
	refNode = document.getElementById(tagID);
	
	if (document.selection) {
		var range = document.body.createTextRange();
		range.moveToElementText(refNode);
		range.select();
		//range.execCommand("Copy");
	} else if (window.getSelection) {
		var range = document.createRange();
		range.selectNodeContents(refNode);
		var selection = window.getSelection();
		selection.removeAllRanges();
		selection.addRange(range);
	}
}
</script>
</head>
<body>
  <div id="d1">This is div 1</div><br /><br />
  <div id="d2">This is div 2</div><br /><br />
  <div id="d3">This is div 3</div><br /><br />
  
  <input type="button" value="1 and 3" onClick="seperateIDs('whatever')" />
</body>
</html>

-Stim
Go to Top of Page

Da_Stimulator
DEV Team Forum Moderator

USA
3373 Posts

Posted - 05 December 2004 :  11:33:05  Show Profile  Send Da_Stimulator an AOL message  Send Da_Stimulator a Yahoo! Message
Ok, I seem to be making progress here, I got the following code to work (yay!)

However, it will only select the latter id (the last one in the array), I have a feeling it's because the copySel function can only select 1 at a time, or something.... but there has to be a workaround, anybody know of one?


<script type="text/javascript">
<!--	
function copySeperate(multipleID) {
multipleID = multipleID.split(",");
var i;
for(i in multipleID)
  copySel(multipleID[i]);
}
function copySel(tagID){
	refNode = document.getElementById(tagID);
	
	if (document.selection) {
		var range = document.body.createTextRange();
		range.moveToElementText(refNode);
		range.select();
		//range.execCommand("Copy");
	} else if (window.getSelection) {
		var range = document.createRange();
		range.selectNodeContents(refNode);
		var selection = window.getSelection();
		selection.removeAllRanges();
		selection.addRange(range);
	}
}
//-->
</script>

-Stim
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Topic Locked
 Printer Friendly
Jump To:
Snitz Forums 2000 © 2000-2021 Snitz™ Communications Go To Top Of Page
This page was generated in 0.32 seconds. Powered By: Snitz Forums 2000 Version 3.4.07