J
jomla
Hi at all
having an imput text like:
<input type="text" name="text1" id="text1" size=40 />
I want to unsert into this field some characters from js at cursor position
or replacing a lot (one or more) selected characters.
I tryed a js like:
function insert(id,str)
{
var range;
if(document.all)
{
var cDoc= document.getElementById(id);
range=cDoc.selection.createRange();
range.text=str;
} else if (window.getSelection)
cWin = document.getElementById(id);
userSelection = cWin.getSelection();
userSelection=str;
cWin.document.execCommand('insertHTML',false,userSelection);
}
}
id parameter is <input id>
str is character to insert
This js work with a <textarea> but not into a <input>
Thanks for any answer
having an imput text like:
<input type="text" name="text1" id="text1" size=40 />
I want to unsert into this field some characters from js at cursor position
or replacing a lot (one or more) selected characters.
I tryed a js like:
function insert(id,str)
{
var range;
if(document.all)
{
var cDoc= document.getElementById(id);
range=cDoc.selection.createRange();
range.text=str;
} else if (window.getSelection)
cWin = document.getElementById(id);
userSelection = cWin.getSelection();
userSelection=str;
cWin.document.execCommand('insertHTML',false,userSelection);
}
}
id parameter is <input id>
str is character to insert
This js work with a <textarea> but not into a <input>
Thanks for any answer