found a script on a site that will allow me to double-click to edit a span, and I’ve modified it heavily. Even before I modded it it would randomly crash Safari, and I can’t find a fix anywhere. If someone could even clean this up, even if it doesn’t fix the problem I’d be greatful, just started working with Javascript today…
[code]
function data() {
};
data.prototype.initiate = function() {
try {
// safari, firefox (yay)
this._xh = new XMLHttpRequest();
}
catch (e)
{
// yuck! internet explorer!
var _iemodels = new Array(
‘MSXML2.XMLHTTP.5.0’,
‘MSXML2.XMLHTTP.4.0’,
‘MSXML2.XMLHTTP.3.0’,
‘MSXML2.XMLHTTP’,
‘Microsoft.XMLHTTP’
);
var success = false;
for ( var i = 0; i < _iemodels.length && !success; i++ )
{
try {
this._xh = new ActiveXObject( _iemodels[i] );
success = true;
}
catch (e)
{
// trap
}
}
if ( !success )
{
return false;
}
return true;
}
}
data.prototype.occupied = function() {
actualState = this._xh.readyState;
return ( actualState && ( actualState < 4 ) );
}
data.prototype.process = function() {
if ( this._xh.readyState == 4 && this._xh.status == 200 )
{
this.processing = true;
}
}
data.prototype.send = function( urlget, data ) {
if ( !this._xh )
{
this.initiate();
}
if ( !this.occupied() )
{
this._xh.open( “GET”, urlget, false );
this._xh.send( data );
if ( this._xh.readyState == 4 && this._xh.status == 200 )
{
return this._xh.responseText;
}
}
return false;
}
http = new data;
function _gr(reqseccion,divcont) {
nt = http.send(reqseccion,””);
document.getElementById(divcont).innerHTML = nt;
}
function change( nn, actual )
{
elem = document.getElementById( nn );
elem.innerHTML = “<input type=”text” value=”” + actual.innerHTML + “” onkeypress=”return keepEnter(this, event, ‘” + nn + “‘ )” onblur=”return keepBlur( this, ‘” + nn + “‘ )” />”;
elem.firstChild.focus();
}
var urlBase = “index.php?page=ajax&”;
function keepEnter( field, evt, idfld )
{
evt = (evt) ? evt : window.event;
if ( evt.keyCode == 13 && field.value != “” )
{
field.value = field.value.replace(“/|/”,””);
elem = document.getElementById( idfld );
nt = http.send(urlBase + elem.id + “=” + escape( field.value ), “” );
elem.innerHTML = “<span ondblclick=”change( ‘” + idfld + “‘, this );”>” + nt + “</span>”;
return false;
}
else
{
return true;
}
}
function keepBlur( field, idfld )
{
if ( field.value != “” )
{
field.value = field.value.replace( “/|/”, “” );
elem = document.getElementById( idfld );
nt = http.send(urlBase + elem.id + “=” + escape( field.value ), “” );
elem.innerHTML = “<span ondblclick=”change( ‘” + idfld + “‘, this );”></span>”;
elem.firstChild.innerHTML = nt;
return false;
}
}