views:

116

answers:

3

So ... The thing is, the code works in FireFox, no problems. But when I open the same page, it gives me the following error:

"Undefined is null or not an object."

But when I copy the code to a localhost page, it works fine. Also when I clear my cache in IE it works, but only once, if I refresh after that one load, it gives me the same error.

Here is the code:

<script type="text/javascript" src="datepicker/js/jquery-1.4.2.min.js"></script>
<script type="text/javascript">
     var count3 = 0; 
     var count5 = 0;
     var count2 = 0;
     var count4 = 0;

    $(document).ready(function(){

    $('#switch3').click(function(){
        $('#switchDiv3').slideToggle(350);
            if(count3 == 0){
            count3 = 1;
            document.getElementById('switchImage3').src = "images/ArrowDown.png";
            return;
            } else {
            count3 = 0;
            document.getElementById('switchImage3').src = "images/ArrowRight.png";
            return;
            }
    });

    ... (this is the code for each item that is generated) 
    </script>

And the code that determines the div that should hide:

<table width="100%" border="0" cellspacing="0" cellpadding="0" align="center">
    <tr>
        <td width="20" align="center" valign="top" style="padding-right: 3px">
            <a style="cursor: pointer;" id="switch3"><img width="20" height="20" src="images/ArrowRight.png" id="switchImage3" style="border-style: solid; border-width: 1px; border-color: black;"/></a>
        </td>
        <td>
            <div id="switchDiv3">
                <div align="left">
                    (Contents of the div here)
                </div>
            </div>
        </td>
    </tr>
</table>

Any help is appreciated!

Thanks in advance

A: 

You need to describe what you want to do. I guess you want to show and hide a div and switch an arrow from left to right when you do.

You could use the toggle function, its really cool, heres an exemple of something near you want (i guess).

<html>
<head>
    <script type="text/javascript" src="jquery-1.4.2.min.js"></script>

    <script type="text/javascript">
        $(document).ready(function(){
            $("#switch3").toggle(function(){
                $("#switch3").html('<-');
                $("#switchDiv3").slideToggle(350);;

            }, function(){
                $("#switch3").html('->');
                $("#switchDiv3").slideToggle(350);
            });
        });
    </script>
</head>
<body>
    <div>
    <a id="switch3" style="cursor: pointer;"> -> </a>
        <div id="switchDiv3" style="background-color: red">
        Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
        </div>
    </div>
</body>

By the way, i used inline styling only for the exemple, you should use external stylesheet.

Richard Rail
I have found the problem, or at least I think I did :pThe company I'm currently placed in for my internship (school thingy ...) didn't inform me that they also used the Prototype 1.5 framework. So I'm guessing that the two frameworks are interfering with each other ...So all I have to try now is to create the same function using Prototype, but that is gonna take a while since I have never worked with that one ...Thanks anyway for the help on this matter ^^
Syncopated
oh, now thats not cool. a framework + a librarie. Good luck.
Richard Rail
@syncopated: the two libraries are interoperable with each other. Check out the jquery docs for how you can use a symbol other than $ to access the jq library. I'd look up the link for you, but I'm unfortunately on a mobile phone at the moment. :\
Faisal
e.g jquery('html').remove();its just longer, but do you really need 2 libraries that do the same thing? Maybe 2-3 function different
Richard Rail
A: 

So ...

The prototype function didn't work either, no clue as to why ... So now I'm just gonna try to change the display attribute.

No luck either. The script changes the arrow, but it doesn't hide the div ...

Here is the code:

var count3 = 0;
function showHideDiv3(){
    if(count3 == 0){
        document.getElementById('switchDiv3').style.display = '';
        document.getElementById('switchImage3').src = "images/ArrowDown.png";
        count3 = 1;
    }else{
        if(count3 == 1){
            document.getElementById('switchDiv3').style.display = 'block';
            document.getElementById('switchImage3').src = "images/ArrowRight.png";
            count3 = 0;
        }
    }
}

The names of the div's are correct. I have checked, and 3 of my colleagues have also doublechecked.

This is driving me crazy and depressed lol.

Syncopated
Please update your original question to reflect this.
svinto
A: 

Are you just trying to swap icons to indicate status? If so, just select the src attribute of an id placed on the image and swap graphics.

So, use something like:

$('#swtichImage3').hover(function() {
$(this).attr('src', 'images/ArrowDown.png');
}, function(){
$(this).attr('src', 'images/ArrowRight.png');
});

In that example, I'm using the hover() action but you can swap that. I just wanted to put that to show an easier way of swapping src attribute.

Billy