JavaScript SRC path not working

I have searched this web looking for an answer, but it seems that this time I'm not so lucky, so I am forced to ask. I apologize if it's already answered (could not find it). And yes, English is not my first language, so I also apologize for my spelling mistakes, I try my best.

This is my problem, using Tomcat 5.5, Struts 1.3, JRE 1.5 and I'm using firefox 3.5.6. In my jsp page I cannot seem to put any src="path/path" in my <script> I have tried deleting the src and all works well, but my project is going to need a lot of use from jquery and I do not want to copy/paste all the js file in every jsp.

This is my code:

<script type="text/javascript" src="js/jquery-1.3.2.js">
    function showMySelf(){
        alert("Hello World!");      
    }
(... plus other stuff code that actually uses jquery functions)
</script>

and the submit button:

<input type="submit" onclick="showMySelf()">

When I click the button, nothing happens (well it actually repaints the page) and when I delete the "src" tag from the script and add all the jquery code to the page it all works well.

I have tried putting another slash in the path as "/js/jquery-1.3.2.js" and returns an error.

I have tried using ResolveURL and it doesn't seem to give me better results.

I have also tried changing the js file to another file ("generics.js" and "js.js"), I also tried with "js/*.js".

Any of theese solutions have archived anything.

I have also tried using the struts tags (like html:submit) but it also did not work.

The path is actually right, since looking the code in my web browser gives me a link to the js file. So I suposse the browser knows were to look for my js file, it does not give me an error or a broken link to the file.

Any ideas of why this is happening?

Thank you all.

Random.

Answers


You can not use a script element to load an external file and put code in it at the same time. You need to use two script elements:

<script type="text/javascript" src="js/jquery-1.3.2.js"></script>
<script type="text/javascript">
    function showMySelf(){
        alert("Hello World!");      
    }
(... plus other stuff code that actually uses jquery functions)
</script>

Need Your Help

Is the connection Pool configuration kept outside JPA Context?

java jpa persistence eclipselink connection-pooling

Hello i am extracting the connection object from the EclipseLink context by calling: Connection con = entityManager.unwrap(Connection.class);

C# british summer time (BST) timezone abbreviation

c# .net timezone

I need to display a label with the current time zone abbreviation. My pc's timezone is currently set to "(GMT) Greenwich Mean Time : Dublin, Edinburgh, Lisbon, London". As a result, I would like ...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.