whammy
02-20-2003, 10:25 PM
Hello,
A colleague and I are trying to find a way to automatically select ONLY a specific range of text within a page, using
document.body.createTextRange()
and somehow referencing the id of a span... however NOTHING we have tried works. We got it to select the first thing sometimes (they may often contain the same text), and at other times it would select all spans with identical text - but we're finding it impossible to isolate the span by id and select the text just by clicking on the span. It's pretty perplexing, and this is not the type of javascript we usually mess around with... any help?
The below obviously doesn't work, just a general example of what we're trying to do... :mad:
<html>
<head>
<title></title>
<script type="text/javascript">
<!--
function textSelect(lblnumber)
{
alert(lblnumber);
var range = document.???.innerText;
range.createRange();
range.select();
}
// -->
</script>
</head>
<body>
<form id="form1" action="" method="post">
<span id="lblFasdffname" onclick="textSelect(this.id)"><*fname*></span>
<span id="lblFasd234name" onclick="textSelect(this.id)"><*fname*></span>
<span id="lblFasdasd3name" onclick="textSelect(this.id)"><*fname*></span>
</form>
</body>
</html>
A colleague and I are trying to find a way to automatically select ONLY a specific range of text within a page, using
document.body.createTextRange()
and somehow referencing the id of a span... however NOTHING we have tried works. We got it to select the first thing sometimes (they may often contain the same text), and at other times it would select all spans with identical text - but we're finding it impossible to isolate the span by id and select the text just by clicking on the span. It's pretty perplexing, and this is not the type of javascript we usually mess around with... any help?
The below obviously doesn't work, just a general example of what we're trying to do... :mad:
<html>
<head>
<title></title>
<script type="text/javascript">
<!--
function textSelect(lblnumber)
{
alert(lblnumber);
var range = document.???.innerText;
range.createRange();
range.select();
}
// -->
</script>
</head>
<body>
<form id="form1" action="" method="post">
<span id="lblFasdffname" onclick="textSelect(this.id)"><*fname*></span>
<span id="lblFasd234name" onclick="textSelect(this.id)"><*fname*></span>
<span id="lblFasdasd3name" onclick="textSelect(this.id)"><*fname*></span>
</form>
</body>
</html>