Aggiornamento:
codice:
<html>
<head>
</head>
<body>
<input type="text" name="tuoTesto" value="qui il tuo testo" id="input" readonly>
<script type="text/javascript" >
//Sposta il cursore a fine testo
var _SetCursorPosition=function(input){
if(typeof(input)!='object')
return false;
var end=input.value.length;
if(input.createTextRange){ //IE
var range = input.createTextRange();
range.move("character", end);
range.select();
} else if(input.selectionStart)//standard browser
input.setSelectionRange(end, end);
return true;
}
//Add event cross browser
var addEvent=function(obj,evt,fnc){
if(typeof(obj)!='object')
return false;
if(typeof(evt)!='string')
return false;
if(typeof(fnc)!='function')
return false;
if(obj.addEventListener)//standard browser
obj.addEventListener(evt,fnc,false);
else if(obj.attachEvent)//IE
return obj.attachEvent('on'+evt,fnc);
else obj['on'+evt]=fnc;
}
//Remove event croos browser
var removeEvent=function(obj,evt,fnc){
if(obj.removeEventListener)
obj.removeEventListener(evt,fnc,false);//standard browser
else if(obj.detachEvent)//IE
return obj.detachEvent('on'+evt,fnc);
}
//Stoppa l'azioen di default dell'evento e senza stopparne la propagazione
var preventDefault=function(e){
if(window.event)
e.returnValue=false;
else
e.preventDefault();
}
var _focus=function(){
this.readOnly=false;
this.focus();
removeEvent(input,'mousedown',preventDefault);//mousedown attivo quando il focus e' sulla textbox
this.onclick='';
_SetCursorPosition(this);
}
var input=document.getElementById('input');
addEvent(input,'mousedown',preventDefault);//niente focus al mousedown
//focus su click
input.onclick=_focus;
//reset
input.onblur=function(){
this.readOnly=true;
addEvent(input,'mousedown',preventDefault);//disabilito di nuovo il mousedown
this.onclick=_focus;
}
</script>
</body>
</html>
COn questo codice, il focus sulla textbox e' sempre al mousedown pero', diversamente da prima, solo al click la textbox diventa editabile. E' il meglio che sono riuscito a fare, posto nel caso sia utile a qualcuno