|
|||||||
| JavaScript JavaScript (not Java) Discussion and technical support, including AJAX and frameworks (JQuery, MooTools, Prototype...) |
![]() |
|
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
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
|
||||
|
||||
|
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
|
|||
|
|||
|
Thank you very much, worked perfectly!!
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|