Discover > Answered Question
![]() |
Query about createRange for textarea in javascripe
Asked by: tanishka
from Pune, India
|
i shift value from list to rich textarea in specified position but it does not work for
document.selection .it produced undefined value so it can't go in loop
following is my function
my browser is Netscape and version>4
function shiftvalue(frm)
{
if(document.frm.columnName.value=="")
{
alert("Please Select Mail Parameter");
return false;
}
else
{
var tn=document.frm.dsrte_text;
var shiftValue = frm.columnName.options[frm.columnName.selectedInde
x].value;
alert(shiftValue);
//IE support
if (document.selection)
{
tn.focus();
sel = document.selection.createRange();
sel.text = shiftValue;
alert(sel.text)
}
//MOZILLA/NETSCAPE support
else if ((tn.selectionStart == 0) && (tn.selectionEnd == 0))
{
tn.value += shiftValue;
alert(tn.value);
}
else
{
var startPos = tn.selectionStart;
var endPos = tn.selectionEnd;
tn.value = tn.value.substring(0, startPos) + " " + shiftValue + " " + tn.value.substring(endPos, tn.value.length);
}
return false;
}
}
here i call that function
<input type="button" name="btnShift" value="<<" onclick="return shiftvalue(this.form);" >
document.selection .it produced undefined value so it can't go in loop
following is my function
my browser is Netscape and version>4
function shiftvalue(frm)
{
if(document.frm.columnName.value=="")
{
alert("Please Select Mail Parameter");
return false;
}
else
{
var tn=document.frm.dsrte_text;
var shiftValue = frm.columnName.options[frm.columnName.selectedInde
x].value;
alert(shiftValue);
//IE support
if (document.selection)
{
tn.focus();
sel = document.selection.createRange();
sel.text = shiftValue;
alert(sel.text)
}
//MOZILLA/NETSCAPE support
else if ((tn.selectionStart == 0) && (tn.selectionEnd == 0))
{
tn.value += shiftValue;
alert(tn.value);
}
else
{
var startPos = tn.selectionStart;
var endPos = tn.selectionEnd;
tn.value = tn.value.substring(0, startPos) + " " + shiftValue + " " + tn.value.substring(endPos, tn.value.length);
}
return false;
}
}
here i call that function
<input type="button" name="btnShift" value="<<" onclick="return shiftvalue(this.form);" >
No Clarification Requests
Answer
|
User Rating:
![]() ![]() ![]() ![]()
Answer Compliments:
0
|
O'Reilly Network -- Using JavaScript to Create a Powerful GUIcreateRange() implementation is currently broken in Mozilla, specifically in its inability to manipulate text in an input element or textarea element.
http://www.oreillynet.com/pub/...
thelist] Using Javascript to add tags to selected text in textarea[thelist...
http://www.oreillynet.com/pub/...
thelist] Using Javascript to add tags to selected text in textarea[thelist...
Answer Date: 10:59pm 05/12/08









