views:

72

answers:

2

Disregard this question: I've simply confused <script src="..."></script> tag and <script> [some functions] </scipt> tags.

I have this function

function OnLoad()
{
    ShowHideConfirmAnswers();

    return true;
}

triggered by onload event:

<body onload=OnLoad()>

It works fine until I add src="jquery-1.4.2.js" to the script element. From this moment I get "OnLoad is not defined" error, and the same happens to every other javascript function.

A: 

What happens if you change the OnLoad call to this script block ?

$(document).ready(function(){
  ShowHideConfirmAnswers();
}

And just remove the OnLoad="" block from the Html.

Russ C
Also, this approach encourages you to write your Javascript consistently. You might even consider in-lining ShowHideConfirmAnswer().
Russ C
+1  A: 

It works fine until I add src="jquery-1.4.2.js" to the script element.

This line makes me think you're using a script element like this:

<script type="text/javascript">
    //... all code here
</script>

And then you're adding the src attribute to the element:

<script type="text/javascript" src="jquery-1.4.2.js">
    //... all code here
</script>

Which won't work. Once you add the src attribute to a <script> element, all data contained within the script element will be completely ignored by the browser. You have to use separate script tags for external and inline javascript:

<script type="text/javascript" src="jquery-1.4.2.js"></script>
<script type="text/javascript">
    //... all code here
</script>
Andy E