www.webdeveloper.com
Results 1 to 3 of 3

Thread: [RESOLVED] Javascript in Firefox - doctype problem - id not defined?

  1. #1
    Join Date
    Nov 2009
    Posts
    2

    resolved [RESOLVED] Javascript in Firefox - doctype problem - id not defined?

    Hello,
    I really need some help. I have been struggling with this script all day and haven't found any solution.

    <script type="text/javascript">

    function toggleButton(ktory,ile,id_obrazka,f,q) {
    for (i=0; i<ile; i++) {
    eval('wybor'+i).className='';
    }
    if (document.getElementById) {
    eval(document.getElementById('wybor'+ktory)).className = 'active';
    document.getElementById(id_obrazka).setAttribute('src',f + q+'.jpg')
    }
    else if (document.all) {
    eval(document.all['wybor'+ktory]).className = 'active';
    document.all[id_obrazka].setAttribute('src',f + q+'.jpg')
    }
    }

    </script>




    <img id="wywiady" src="22.jpg"></td>

    <a class="active" id="wybor0" href= "#" onMouseOver="toggleButton(0,2,'wywiady','/zawodnicy/images/mini/','22')"> test 1 </a><BR/>

    <a class="" id="wybor1" href= "/news.html?pokaz_news=10554" onmouseover="toggleButton('1','2','wywiady','/zawodnicy/images/mini/','55')" > test 2</a>


    The problem is that it stops working at all in Firefox with the DoCTYPE declaration <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd"> (or strict). It works only when I run it without any declaration or <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">. The script works in every other browser tested in each of those DOCtypes.

    I also found out that the webdeveloper tool in FF shows 'wybor0 is not defined'. What can it be?

    Thank you very much in advance for help.

    tadziak

  2. #2
    Join Date
    Apr 2003
    Location
    Netherlands
    Posts
    21,654
    Eval is unnecessary
    Code:
    function toggleButton(ktory,ile,id_obrazka,f,q) {
    for (var i=0; i<ile; i++) {
    document.getElementById('wybor'+i).className='';
    }
    if (document.getElementById) {
    document.getElementById('wybor'+ktory).className = 'active';
    document.getElementById(id_obrazka).setAttribute('src',f + q+'.jpg');
    }
    else if (document.all) {
    document.all['wybor'+ktory].className = 'active';
    document.all[id_obrazka].setAttribute('src',f + q+'.jpg');
    }
    }
    At least 98% of internet users' DNA is identical to that of chimpanzees

  3. #3
    Join Date
    Nov 2009
    Posts
    2
    Thank you very much, worked perfectly!!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles