Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Jquery function is not working

 
hemanth acharya
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

Filename: directory_structure.bmp
Description: directory structure
File size: 770 Kbytes
[Download directory_structure.bmp] Download Attachment
 
olivier dutranoit
Ranch Hand
Posts: 81
IBM DB2 Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 81
IBM DB2 Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 81
IBM DB2 Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Solved the issue,

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



Regards,
hemanth.
 
olivier dutranoit
Ranch Hand
Posts: 81
IBM DB2 Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
oliver,

Thanks a lot for the description...


regards,
hemanth
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic