Win a copy of TDD for a Shopping Website LiveProject this week in the Testing forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

call javascript function from java class

 
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I have a check box in JSP page.When click on this checkbox, "knowlegecheck()" function is called in javascript.

This pages comes from action class(Struts).

I want to call this method "knowlegecheck()" in Action java class.so when this page loads, directely call this method.so no need to click on check box.

How can I call java script method in java class ?
Please help me.

Thanks,
Nimish
 
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
JavaScript can no talk with the server you need to post back the page in some manner. You can do it with a forced form submission with document.forms[0].submit() or you can go the Ajax route (plenty of tutorials online for Ajax).

Eric
 
Sheriff
Posts: 67634
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you want it to happen at page load, you can place it in the onload handler.

But as Eric said, there can be no direct communication between the server-side JSP and the client-side Javascript. Perhaps this article could help explain why.
 
You can't have everything. Where would you put it?
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic