469,307 Members | 2,083 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,307 developers. It's quick & easy.

How can we call a javascript function present in another jsp file.?

10
<script type="text.javascript" src="/NewPrototype/jsp/caldata.jsp"></script>

I am trying to call javascript function named( show() ) from index.jsp which is present in caldata.jsp but it is not calling that function.

How we can call a function which is present in script of another jsp page?
May 28 '10 #1
8 17034
Dormilich
8,651 Expert Mod 8TB
maybe this works
Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript" src="/NewPrototype/jsp/caldata.jsp"></script>
otherwise consult the error console.
May 28 '10 #2
aaaash
10
@Dormilich
Thanks for your reply..
I checked in error console it says show() func is not defined.Now what i need to do?
Thanks in advance
May 28 '10 #3
Dormilich
8,651 Expert Mod 8TB
check if you can manually call the JavaScript file in the browser (via address bar).
May 28 '10 #4
aaaash
10
As you suggested i manually called that jsp page where javascript is present it is displaying the content.
To get better idea of what I am doing, I am posting code which is in complete..
in index.jsp

Expand|Select|Wrap|Line Numbers
  1. <A HREF="javascript:void(null);" onclick="showFilterChoices('Language');">
  2. <script type="text/javascript" src="/NewPrototype/jsp/caldata.jsp"></script>
in caldata.jsp
i have defined showFilterChoices function like this

Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript">
  2. function showFilterChoices( whichFilter )
  3. {
  4. }
  5.    </script>
What may be the error here?
May 28 '10 #5
Dormilich
8,651 Expert Mod 8TB
external JavaScript files do not use <script> tags (that is for HTML pages to denote a JS section).

your JSP file should send a javascript header.

I suppose your function is not empty in reality.
May 28 '10 #6
aaaash
10
@Dormilich
Yes my function is not empty..

Can u plz tell how can jsp file send a js header..?? Give Ex

In caldata.jsp i am writing some function in <body> of it.So i wrote js function within <script>

Thanks you in advance..
May 28 '10 #7
Dormilich
8,651 Expert Mod 8TB
Can u plz tell how can jsp file send a js header..?? Give Ex
sorry, I’m not a Java guy. I could tell you how to do it in PHP though …

In caldata.jsp i am writing some function in <body> of it.So i wrote js function within <script>
that means, you include an entire HTML page via <script>? no wonder it doesn’t work …

an external JavaScript file must only contain pure JavaScript code. that is, no tags around it.
May 28 '10 #8
aaaash
10
@Dormilich
OK. Thanks for your suggestion.
May 28 '10 #9

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

2 posts views Thread by Matthew Louden | last post: by
1 post views Thread by hrishikesh | last post: by
17 posts views Thread by sagar | last post: by
reply views Thread by harlem98 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.