i need to set the Clint focus on my input filed
<input type="text" name="fname" id="fname" onfocusout="myFunction8()">
onfoucseout, and i want it to focus at cirtain place on the input (for exaple, position 2: "he[cursor]llo")
function myFunction8()
{
var str = document.getElementById("fname")
var l = str.length
var l = 0
var n = 0
var d = 0
var s=0
if (l < 5) {
//the carsure will be foucused in position 0
}
else {
for (var i = 0; i < str.length; i++) {
if ((str.charAt(i)) = "@") {
l++;
n = i
}
if ((str.charAt(i)) = ".") {
d++
l = i
}
}
}
if (l == 0) {
//the carsure will be foucused in position 1
}
if (d == 0) {
//the carsure will be foucused in position 3
}
if (l > 1) {
//the carsure will be foucused in position n
}
if ((l - n) < 2) {
//the carsure will be foucused in position n+1
}
if (n==0) {
//the carsure will be foucused in position 0
}
if (l==0) {
//the carsure will be foucused in position 0
}
}
note: this articel was not helful becuse it not using vanila js and: this one as well as this one was not helpful becuse they fouce non foucing the curscur on the input fhils, but not use the exact position