Bogdan
Bogdan

Reputation: 1901

Why does this script tag not run this script on page load?

This is the simple script i'm trying to run, i've also tried it with only the alert but it just doesn't work. If it's any help, it's part of a html block i'm echoing from a php script.

<script type="text/Javascript">    
    alert(\'test\');      
    JACS.show(document.getElementById(\'data_jacs\'),\'jacsStatic2\');                                                                                     
</script>

I found the problem and it has nothing to do with the script, it has everything to do with the php file i'm echoing it from being loaded with AJAX. Thanks for the help.

Upvotes: 0

Views: 3528

Answers (3)

yapingchen
yapingchen

Reputation: 856

You should put this code behind the tag.

Or you can do:

window.onload=function(){
    alert(\'test\');      
    JACS.show(document.getElementById(\'data_jacs\'),\'jacsStatic2\');                                                                                     
}

Upvotes: 0

Hemant Metalia
Hemant Metalia

Reputation: 30638

it returns error so to execute it and catch exception you need to specify try catch block

<script>    
  alert('test');   
  try
  {   
     JACS.show(document.getElementById('data_jacs'),'jacsStatic2');                                                                                     
}
catch(err){
   alert(err);
}
</script>

it alerts an error JACS library not defined.

Upvotes: 0

Bart Vangeneugden
Bart Vangeneugden

Reputation: 3446

Might be more then one reason:

  1. Don't use slashes:

    alert('test');

  2. You're using JACS. Are you sure the JACS library is loaded by the time this script tag is being executed?

Upvotes: 1

Related Questions