views:

60

answers:

3

I have a javascript where I need to hide (and eventually show) some text by clicking a button. However, when I click the button, it does not call the function specified in the onclick parameter, and so nothing happens. Here is my source code:

<script type="text/javascript">
        $(document).ready(function(){                   
            var tip = 1;
            $(".tip1").hide();
            $(".tip2").hide();          
            switch (tip) {
                case 1:
                    $(".tip1").show();
                    break;
                case 2:
                    $(".tip2").show();
                    break;
            }           
            function nextTip() {
                $(".tip1").hide();

                return;
            }
        });
    </script>
    <br/>
    <div id='bg_container' style='background-image: url("<?=$PICS?>trackingpage_middle.jpg")' >
    <img style='z-index:-1;' width='737px' src='<?=$PICS?>trackingpage_top.jpg'>
    <div id='main_container' >
        <form>
            <input type="button" onClick="nextTip()" value = "Next Tip" />
        </form>
        <div class="tip1">

... and so on.

+1  A: 

Have you tried moving the function nextTip() out of $(document).ready to the global scope?

KennyTM
Wonderful, that was the problem. Thank you.
nsw1475
@nsw1475: you can mark his answer as "Accepted".
Wadih M.
A: 

Take the nextTip() out of the $(document).ready(function(){} portion.

Wadih M.
A: 

Since It seems you are using jQuery why don't you add:

$('input[type="button"]').click(function(){ $(".tip1").hide();});

to your $(document).ready( ... ) code ?

microspino

related questions