Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
The moose likes HTML, CSS and JavaScript and the fly likes Jquery function is not working Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Jquery function is not working" Watch "Jquery function is not working" New topic
Author

Jquery function is not working

hemanth acharya
Ranch Hand

Joined: Aug 10, 2011
Posts: 51
Hello all,

I am new to Jquery and stuffs, so quite hanged-up with an initial hick-up..

I have the following jsp page, which does a basic alert pop-up on button click.




I have attached my directory structure is the following..

can anyone let me know where i am going wrong, any help is greatly appreciated.

Thanks and regards,
Hemanth.



[Download directory_structure.bmp] Download

olivier dutranoit
Ranch Hand

Joined: Aug 20, 2011
Posts: 81

Hi,

tried your code, works fine!

Be sure you use the right jquery libraries.
actually, you just need 1 *.js file for this basic example.

Try downloading the latest jquery library to be sure you have the right one.

hemanth acharya
Ranch Hand

Joined: Aug 10, 2011
Posts: 51
Hi olivier ,

Thanks for quick response,
May i know which one is the *.js that is required.. cause i have all the required js in my directory structure.. did you have a look at it?

Thanks and regards,
hemanth.
olivier dutranoit
Ranch Hand

Joined: Aug 20, 2011
Posts: 81

I didn't look at your structure, because i cannot download anything for the moment (behind secured firewall)...

but, try downloading this js file:

http://code.jquery.com/jquery-1.6.4.min.js

and just for test purposes, try following:

<script type="text/javascript" src="http://code.jquery.com/jquery-1.6.4.min.js"></script>

if this works, save the js locally in your application.
olivier dutranoit
Ranch Hand

Joined: Aug 20, 2011
Posts: 81

managed to view your structure.

Seems good to me...

only thing is,

<script type="text/javascript" src="jquery.js"></script>

i see nowhere "jquery.js" in your structure.

as i said

download "jquery-1.6.4.min.js", put it in your js directory, and use

<script type="text/javascript" src="js/jquery-1.6.4.min.js"></script>
hemanth acharya
Ranch Hand

Joined: Aug 10, 2011
Posts: 51
olivier,

Thanks for the response,

I will do as you mentioned, and will get back to you..


Thanks and regards,
hemanth.
hemanth acharya
Ranch Hand

Joined: Aug 10, 2011
Posts: 51
olivier,

Its still the same,

It never seem to fire the event for button click...

Do you have any idea what else might be the reason??

Thanks and regards,
hemanth.
hemanth acharya
Ranch Hand

Joined: Aug 10, 2011
Posts: 51
Solved the issue,

I put the onclick part of jquery inside the $function().... Here is the code..



Regards,
hemanth.
olivier dutranoit
Ranch Hand

Joined: Aug 20, 2011
Posts: 81

ow i see, stupid me :-)

the reason it worked here, is because i placed the script AFTER the form. So, the html code is being parsed by the browser, and THEN the script is parsed. So the browser knows about what the script is talking.

But, if the script is placed before that form (without the function() ) the script is parsed before the html is parsed. So it does not know about what it is talking.

now, the "$(function()" tells the browser to "parse" the script, after the page is loaded. So, wherever you put your script code with that "function", it will always work.

Actually, the best place for scripts, is always in the bottom of your page, to be sure they certainly work.
hemanth acharya
Ranch Hand

Joined: Aug 10, 2011
Posts: 51
oliver,

Thanks a lot for the description...


regards,
hemanth
 
wood burning stoves
 
subject: Jquery function is not working
 
Similar Threads
Getting duplicate values on the onChange event of dropdown list
calling jsp page using Jquery
my overlay box works in Firefox, but fails in IE8
radio button error problem?
Creating a masked popup in JavaScript