Solved

Call javascript from jsp

Posted on 2007-11-15
3
5,372 Views
Last Modified: 2008-02-01
Hello Everyone,

I have a jsp page which acts as a template in the main page, the jsp page does not have any body tags,I want to call a javascript function within this jsp page whenever the page is loaded or refreshed. Usually in a html body tag you could call it in the onLoad event, how would i call it without the body tag.

Thank you
Harsha
0
Comment
Question by:gbvreddy
  • 2
3 Comments
 
LVL 27

Expert Comment

by:rrz
ID: 20292682
What does the javascript do ?  
>how would i call it without the body tag.  
Doesn't the JSP output ultimately end up in the body tag of the enclosing page ?
0
 
LVL 35

Accepted Solution

by:
TimYates earned 500 total points
ID: 20297330
You could try just sticking the javascript at the bottom of your template...  Then the full DOM won't have finished loading, but at least this part of it will have...

<div>
  <%= "Woo! I'm a JSP with no body" %>
</div>
<script type="text/javascript">
  alert( 'and I'm some javascript' );
</script>

Open in new window

0
 
LVL 35

Expert Comment

by:TimYates
ID: 20297333
(obviously, you should use valid javascript with no escaping errors like mine)

*blush*
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article shows how to create and access 2-dimensional arrays in JavaScript.  It includes a tutorial in case you are just trying to "get your head wrapped around" the concept and we'll also look at some useful tips for more advanced programmers. …
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question