Jump to content

[SOLVED] IE Error - Help Please - Noob


savagenoob

Recommended Posts

I keep getting an error message when I visit the page that references the below javascript page, it says

"Message: Expected '}'

Line: 271

Char: 6

Code: 0

URI: http://www.blahblahblah/filemanager.js"

Here is filemanager.js, line 271 is the last on the page with the }. I checked all the } and they are all there. :wtf:

// retrieve all elements of a given class
function getElementsByClass(search)
{
    var classElements = new Array();
    var els = document.getElementsByTagName('*');
    var pattern = new RegExp('(^|\\s)' + search + '(\\s|$)');
  
    for (var i = 0, j = 0; i  <  els.length; i++)
    {
        if (pattern.test(els[i].className))
        {
            classElements[j] = els[i];
            // retrieve all elements of a given class
function getElementsByClass(search)
{
    var classElements = new Array();
    var els = document.getElementsByTagName('*');
    var pattern = new RegExp('(^|\\s)' + search + '(\\s|$)');
  
    for (var i = 0, j = 0; i  <  els.length; i++)
    {
        if (pattern.test(els[i].className))
        {
            classElements[j] = els[i];
                }
}

// remove the highlighting on mouseout
function unhighlightTableRow(e)
{
    e.style.backgroundColor = '';
}
  
// register event handlers and set initial view
window.onload = function()
{
    window.directory = '/';  // current directory viewed
    window.filename = '';    // currently selected file

    // event handlers
    document.getElementById('btn_open').onclick = openSelected;

    document.getElementById('btn_new_folder').onclick = showNewFolder;
    document.getElementById('form_new_submit').onclick = doNewFolder;
    document.getElementById('form_new_reset').onclick = hideForms;
      
    document.getElementById('btn_upload').onclick = showUploadFile;
    document.getElementById('form_upload').target = 'my_iframe';
    document.getElementById('form_upload_submit').onclick = doUploadFile;
    document.getElementById('form_upload_reset').onclick = hideForms;
  
    document.getElementById('btn_rename').onclick = showRename;
    document.getElementById('form_rename_submit').onclick = doRename;
    document.getElementById('form_rename_reset').onclick = hideForms;

    document.getElementById('btn_delete').onclick = doDelete;

    // load the file listing
    refreshFilesList();
}
  
// retrieve display of files and directories
function refreshFilesList()
{
    hideForms();

    var url = 'process.php?action=list & dir=' + window.directory + ' & nocache=' +
        (new Date()).getTime();

    window.httpObj = createXMLHTTPObject();
    window.httpObj.open('GET', url , true);

    window.httpObj.onreadystatechange = function()
    {
        if (window.httpObj.readyState == 4  &   window.httpObj.responseText)
        {
            // populate the fields
            document.getElementById('file_datagrid').innerHTML =
                window.httpObj.responseText;

            window.filename = '';  // selected file
                    }
    }
  
    window.httpObj.send(null);
}
  
// hide all input forms
function hideForms()
{
    document.getElementById('form_new').style.display = 'none';
    document.getElementById('form_rename').style.display = 'none';
    document.getElementById('form_upload').style.display = 'none';
}
  
// alert user the upload failed
function uploadFailed()
{
    alert('Failed to upload file.');
        hideForms();
}
  
// show form to upload a new file 
function showUploadFile()
{
    hideForms();
    document.getElementById('form_upload').reset();
    document.getElementById('form_upload').style.display = '';
}
  
// set form_upload_directory (allow browser to handle form
// submission)
function doUploadFile()
{
    document.getElementById('form_upload_directory').value = window.directory;
}

// show form to create new folder
function showNewFolder()
{
    hideForms();
    document.getElementById('form_new_name').value = '';
    document.getElementById('form_new').style.display = '';
}

// create a new folder
function doNewFolder()
{
    var url = 'process.php?action=new & dir=' + window.directory + ' &  name=' +
        document.getElementById('form_new_name').value + ' & nocache=' +
        (new Date()).getTime();
  
    window.httpObj = createXMLHTTPObject();
        window.httpObj.open('GET', url , true);

    window.httpObj.onreadystatechange = function()
    {
        if (window.httpObj.readyState == 4   &   window.httpObj.responseText)
        {
            if (window.httpObj.responseText == 'OK')
            {
                refreshFilesList();
            }
            else
            {
                alert('Unable to create directory.');
            }
        }
    }
  
    window.httpObj.send(null);
        return false;
}

// show form to rename a file or directory
function showRename()
{
    // don't rename a parent directory or if no file is selected
    if (window.filename == '..' || window.filename == '')
    {
        return;
    }

    hideForms();
    document.getElementById('form_rename_name').value = window.filename;
    document.getElementById('form_rename').style.display = '';
}

// rename the file or directory
function doRename()
{
    var url = 'process.php?action=rename & dir=' + window.directory +
        ' & oldfile=' + window.filename + ' &  newfile=' +
        document.getElementById('form_rename_name').value + ' &  nocache=' +
        (new Date()).getTime();
  
    window.httpObj = createXMLHTTPObject();
    window.httpObj.open('GET', url , true);
  
    window.httpObj.onreadystatechange = function()
    {
        if (window.httpObj.readyState == 4   &   window.httpObj.responseText)
        {
            if (window.httpObj.responseText == 'OK')
            {
                refreshFilesList();
            }
                        else
            {
                alert('Unable to rename entry.');
            }
        }
    }
   
    window.httpObj.send(null);
    return false;
}

// delete a directory or file
function doDelete()
{
    // don't delete a parent directory or if no file is selected
    if (window.filename == '..' || window.filename == '')
        {
        return;
    }

    if (!confirm('Are you sure you wish to delete?'))
    {
        return;
    }

    var url = 'process.php?action=delete & dir=' + window.directory + ' &  file=' +
        window.filename + ' & nocache=' + (new Date()).getTime();
  
    window.httpObj = createXMLHTTPObject();
    window.httpObj.open('GET', url , true);
  
    window.httpObj.onreadystatechange = function()
    {
        if (window.httpObj.readyState == 4   &   window.httpObj.responseText)
        {
            if (window.httpObj.responseText == 'OK')
            {
                refreshFilesList();
            }
            else
            {
                alert('Unable to delete entry.');
            }
        }
    }
  
   httpObj.send(null);
}

// download the selected file or traverse into the selected directory
function openSelected()
{
    var url = 'process.php?action=open & dir=' + window.directory + ' &  file=' +
        window.filename + ' & nocache=' + (new Date()).getTime();

    window.httpObj = createXMLHTTPObject();
    window.httpObj.open('GET', url , true);
  
    window.httpObj.onreadystatechange = function()
    {
        if (window.httpObj.readyState == 4   &   window.httpObj.responseText)
        {
            var result = eval('(' + window.httpObj.responseText + ')');
            if (result.retType == 'directory')
            {
                window.directory = result.directory;
                refreshFilesList();
            }
            else if (result.retType == 'file')
                        {
                window.location = 'download.php? & dir=' + window.directory +
                    ' & file=' + window.filename + ' &  nocache=' +
                    (new Date()).getTime();
            }
            else
            {
                alert('Unknown error.');
            }
        }
    }
  
    window.httpObj.send(null);
    return false;
    }

 

Link to comment
https://forums.phpfreaks.com/topic/174939-solved-ie-error-help-please-noob/
Share on other sites

I checked all the } and they are all there.

 

No, they are not. There are several missing brackets in the first function.

 

In any even't I see a lot of problems with the code. For example in the first function:

    for (var i = 0, j = 0; i  <  els.length; i++)
    {
        if (pattern.test(els[i].className))
        {
            classElements[j] = els[i];
            // retrieve all elements of a given class
        }
    }

The will keep settin classElements[0] equal to each value in els, so when the loop ends it only has the last value saved.

 

There are also two functions titled getElementsByClass(). I think you just copied and pasted part of the first function by mistake

 

Not tested - just fixed what I thought were mistakes

// retrieve all elements of a given class
function getElementsByClass(search)
{
    var classElements = new Array();
    var els = document.getElementsByTagName('*');
    var pattern = new RegExp('(^|\\s)' + search + '(\\s|$)');
  
    for (var i = 0, j = 0; i  <  els.length; i++)
    {
        if (pattern.test(els[i].className))
        {
            classElements[j] = els[i];
        }
    }
}

// remove the highlighting on mouseout
function unhighlightTableRow(e)
{
    e.style.backgroundColor = '';
}
  
// register event handlers and set initial view
window.onload = function()
{
    window.directory = '/';  // current directory viewed
    window.filename = '';    // currently selected file

    // event handlers
    document.getElementById('btn_open').onclick = openSelected;

    document.getElementById('btn_new_folder').onclick = showNewFolder;
    document.getElementById('form_new_submit').onclick = doNewFolder;
    document.getElementById('form_new_reset').onclick = hideForms;
      
    document.getElementById('btn_upload').onclick = showUploadFile;
    document.getElementById('form_upload').target = 'my_iframe';
    document.getElementById('form_upload_submit').onclick = doUploadFile;
    document.getElementById('form_upload_reset').onclick = hideForms;
  
    document.getElementById('btn_rename').onclick = showRename;
    document.getElementById('form_rename_submit').onclick = doRename;
    document.getElementById('form_rename_reset').onclick = hideForms;

    document.getElementById('btn_delete').onclick = doDelete;

    // load the file listing
    refreshFilesList();
}
  
// retrieve display of files and directories
function refreshFilesList()
{
    hideForms();

    var url = 'process.php?action=list & dir=' + window.directory + ' & nocache=' +
        (new Date()).getTime();

    window.httpObj = createXMLHTTPObject();
    window.httpObj.open('GET', url , true);

    window.httpObj.onreadystatechange = function()
    {
        if (window.httpObj.readyState == 4  &   window.httpObj.responseText)
        {
            // populate the fields
            document.getElementById('file_datagrid').innerHTML = window.httpObj.responseText;
            window.filename = '';  // selected file
        }
    }
    window.httpObj.send(null);
}
  
// hide all input forms
function hideForms()
{
    document.getElementById('form_new').style.display = 'none';
    document.getElementById('form_rename').style.display = 'none';
    document.getElementById('form_upload').style.display = 'none';
}
  
// alert user the upload failed
function uploadFailed()
{
    alert('Failed to upload file.');
    hideForms();
}
  
// show form to upload a new file 
function showUploadFile()
{
    hideForms();
    document.getElementById('form_upload').reset();
    document.getElementById('form_upload').style.display = '';
}
  
// set form_upload_directory (allow browser to handle form
// submission)
function doUploadFile()
{
    document.getElementById('form_upload_directory').value = window.directory;
}

// show form to create new folder
function showNewFolder()
{
    hideForms();
    document.getElementById('form_new_name').value = '';
    document.getElementById('form_new').style.display = '';
}

// create a new folder
function doNewFolder()
{
    var url = 'process.php?action=new & dir=' + window.directory + ' &  name=' +
        document.getElementById('form_new_name').value + ' & nocache=' +
        (new Date()).getTime();
  
    window.httpObj = createXMLHTTPObject();
    window.httpObj.open('GET', url , true);

    window.httpObj.onreadystatechange = function()
    {
        if (window.httpObj.readyState == 4   &   window.httpObj.responseText)
        {
            if (window.httpObj.responseText == 'OK')
            {
                refreshFilesList();
            }
            else
            {
                alert('Unable to create directory.');
            }
        }
    }
    window.httpObj.send(null);
    return false;
}

// show form to rename a file or directory
function showRename()
{
    // don't rename a parent directory or if no file is selected
    if (window.filename == '..' || window.filename == '')
    {
        return;
    }

    hideForms();
    document.getElementById('form_rename_name').value = window.filename;
    document.getElementById('form_rename').style.display = '';
}

// rename the file or directory
function doRename()
{
    var url = 'process.php?action=rename & dir=' + window.directory +
        ' & oldfile=' + window.filename + ' &  newfile=' +
        document.getElementById('form_rename_name').value + ' &  nocache=' +
        (new Date()).getTime();
  
    window.httpObj = createXMLHTTPObject();
    window.httpObj.open('GET', url , true);
  
    window.httpObj.onreadystatechange = function()
    {
        if (window.httpObj.readyState == 4   &   window.httpObj.responseText)
        {
            if (window.httpObj.responseText == 'OK')
            {
                refreshFilesList();
            }
            else
            {
                alert('Unable to rename entry.');
            }
        }
    }
   
    window.httpObj.send(null);
    return false;
}

// delete a directory or file
function doDelete()
{
    // don't delete a parent directory or if no file is selected
    if (window.filename == '..' || window.filename == '')
    {
        return;
    }

    if (!confirm('Are you sure you wish to delete?'))
    {
        return;
    }

    var url = 'process.php?action=delete & dir=' + window.directory + ' &  file=' +
        window.filename + ' & nocache=' + (new Date()).getTime();
  
    window.httpObj = createXMLHTTPObject();
    window.httpObj.open('GET', url , true);
  
    window.httpObj.onreadystatechange = function()
    {
        if (window.httpObj.readyState == 4   &   window.httpObj.responseText)
        {
            if (window.httpObj.responseText == 'OK')
            {
                refreshFilesList();
            }
            else
            {
                alert('Unable to delete entry.');
            }
        }
    }
  
   httpObj.send(null);
}

// download the selected file or traverse into the selected directory
function openSelected()
{
    var url = 'process.php?action=open & dir=' + window.directory + ' &  file=' +
        window.filename + ' & nocache=' + (new Date()).getTime();

    window.httpObj = createXMLHTTPObject();
    window.httpObj.open('GET', url , true);
  
    window.httpObj.onreadystatechange = function()
    {
        if (window.httpObj.readyState == 4   &   window.httpObj.responseText)
        {
            var result = eval('(' + window.httpObj.responseText + ')');
            if (result.retType == 'directory')
            {
                window.directory = result.directory;
                refreshFilesList();
            }
            else if (result.retType == 'file')
            {
                window.location = 'download.php? & dir=' + window.directory +
                    ' & file=' + window.filename + ' &  nocache=' +
                    (new Date()).getTime();
            }
            else
            {
                alert('Unknown error.');
            }
        }
    }
  
    window.httpObj.send(null);
    return false;
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.