views:

85

answers:

1

Hi, I'm changing the form action with:

window.onload = function() {
    document.getElementById('pdf').onclick = addExportEvent;
    document.getElementById('xls').onclick = addExportEvent;
    document.getElementById('xml').onclick = addExportEvent;
    document.getElementById('csv').onclick = addExportEvent;
}

function addExportEvent() {
    data = grid.getAllGridData();
    document.getElementById('dados').setAttribute('value', encodeURIComponent(JSON.stringify(data)));

    formulario = document.getElementById('formulario'); // Line 55!
    formulario.action = 'php/' + this.id + '.php';
    formulario.submit();

    return false;
}

But it doesn't work with Internet Explorer. It returns the following error:

Message: The object doesn't support the property or method.
Line: 55
Character: 2
Code: 0
URI: http://www.site.com/javascript/scripts.js
+1  A: 

I think Andy E's head's comment hit it on the, well, head. You are assigning the correct element, but not declaring it using var which makes IE gag and choke and all kinds of bad stuff. Other browsers handle this just fine. So you are trying to access formulario instead of declaring it, which means it never gets the value of id: formulario

function addExportEvent() {
    var data = grid.getAllGridData();
    document.getElementById('dados').setAttribute('value', encodeURIComponent(JSON.stringify(data)));

    var formulario = document.getElementById('formulario'); // Line 55!
    formulario.action = 'php/' + this.id + '.php';
    formulario.submit();

    return false;
}
Dan Heberden
But formulario is an HTML element and it works in browsers like Firefox, Google Chrome, Opera...Before I was doing:formulario.setAttribute('action', 'php/' + this.id + '.php');
Thomas
Andy was right ^ see revised ^
Dan Heberden
Yeap, Andy was right! I put var keyword and everything is working!Thanks guys!
Thomas
+1 for me being right. Yay!
Andy E