• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 280
  • Last Modified:

Javascript eval method does not work in Firefox

I have an old piece of code in a website which is called after a onMouseOver event. It works flawless in IE (all newer versions),Chrome and Safari but not in Firefox.

The eval() method does not work and therefore in Firefox "Tooltip" is always undefined.
(always returns "undefined" in Firefox)
var Tooltip = eval (ObiektDokumentu + '.' + element + WlasciwoscStylu) ;

function popup (myevent,element) {
if ((NE4 && element != 0) || (IE4 && element !=0)) {
var Tooltip = eval (ObiektDokumentu + '.' + element + WlasciwoscStylu) ;
var Stan = Tooltip.visibility ;
if (Stan == "visible" || Stan == "show") {Tooltip.visibility = "hidden"; }
else {

Open in new window

0
nikomanek
Asked:
nikomanek
1 Solution
 
Dave BaldwinFixer of ProblemsCommented:
Ctl-Shift-J will bring up the Error Console which should tell you why it's not working.
0
 
Dave BaldwinFixer of ProblemsCommented:
The demo code on http://www.w3schools.com/jsref/jsref_eval.asp works in Firefox 7.
0
 
nikomanekAuthor Commented:
Yes, thats how I found out that it always returns "undefined".
Tooltip.visibility is undefined
[Break On This Error] var Stan = Tooltip.visibility ;


Tooltip.visibility is undefined since var Tooltip = eval (ObiektDokumentu + '.' + element + WlasciwoscStylu) ;
always returns undefined. in IE Tooltip is defined with the correct element
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
Dave BaldwinFixer of ProblemsCommented:
You might be leaving out a step.  This page http://www.w3schools.com/jsref/prop_style_visibility.asp says it should be:

Tooltip.style.visibility

??
0
 
nikomanekAuthor Commented:
Below is the complete code (as said, works in all browsers but FF)
var Nowa = 0;
var NE4 = 0;
var IE4 = 0;
var browser = ((navigator.appName)+(parseInt(navigator.appVersion)));
if (parseInt(navigator.appVersion) >= 10){ Nowa = 1; }
else
if (browser == "Netscape4" || browser == "Netscape5") { NE4 = 1;} else {IE4 = 1;}
if (NE4 || IE4 || Nowa)
{
var ObiektDokumentu = (NE4) ? 'document' : 'getElementById('*')';
var WlasciwoscStylu = (NE4) ? '':'.style';
}
function popup (myevent,element) {
if ((NE4 && element != 0) || (IE4 && element !=0)) {
var Tooltip = eval (ObiektDokumentu + '.' + element + WlasciwoscStylu) ;
var Stan = Tooltip.visibility ;
if (Stan == "visible" || Stan == "show") {Tooltip.visibility = "hidden"; }
else {
if (NE4)
{
gora = eval (myevent.pageY +12);
lewo = eval (myevent.pageX -250);
}
if (IE4)
{
gora = eval (event.y +12);
lewo = eval (event.x -250);
}
if (lewo < 2) { lewo = 2 ;}
Tooltip.top = gora;
Tooltip.left = lewo;
Tooltip.visibility = "visible";
}
}
}

Open in new window

0
 
nikomanekAuthor Commented:
Same result with "style"

Tooltip is undefined
[Break On This Error] var Stan = Tooltip.style.visibility ;
0
 
Dave BaldwinFixer of ProblemsCommented:
Before the 'eval', put an 'alert' or document.write with "ObiektDokumentu + '.' + element + WlasciwoscStylu" to see what is there.
0
 
leakim971PluritechnicianCommented:
what about :

function popup (myevent,element) {
if ((NE4 && element != 0) || (IE4 && element !=0)) {
var Tooltiiiiiiiip = eval (ObiektDokumentu + '.' + element + WlasciwoscStylu) ;
var Stan = Tooltiiiiiiiip.visibility ;
if (Stan == "visible" || Stan == "show") {Tooltiiiiiiiip.visibility = "hidden"; }
else {
0
 
nikomanekAuthor Commented:
event is not defined
[Break On This Error] gora = eval (event.y +12);
tooltip.js (line 30)
0
 
hieloCommented:
change:
if (NE4 || IE4 || Nowa)
{
    var ObiektDokumentu = (NE4) ? 'document' : 'getElementById(" * ")';
    var WlasciwoscStylu = (NE4) ? '' : '.style';
}

to:
if (NE4 || IE4 || Nowa)
{
    var ObiektDokumentu = 'document';
    var WlasciwoscStylu = '.style';
}

Open in new window

0
 
BadotzCommented:
// Better to test for functionality rather than browser:
//
var ObiektDokumentu = document.getElementById ? "document.getElementById(*)" : "document";
//
// etc.

Open in new window

0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now