Solved

execute javascript function from jstl <c:if>

Posted on 2015-02-07
3
2,418 Views
Last Modified: 2015-02-08
javascript function is not executing;
getDimentions() is in external javascript file and it is included in jsp file <head></head> tag.

Here is jsp code:

<div>
<c:if test='${not empty dimValues}'>
<script type="text/javascript">
  getDimensions('<%=cubeValue%>');
 </script>
  </c:if>
</div>

Open in new window


Here is javascript code :

function getDimensions(dim1)
{
	document.write(dim1);
	
}

Open in new window

0
Comment
Question by:Pradip Shenolkar
  • 2
3 Comments
 
LVL 27

Accepted Solution

by:
rrz earned 500 total points
ID: 40596502
If you want people to help you, then you should make it easy for them to do so. You should post small(minimal) code that is complete. That way people can copy and paste to test.  Please try running the following code.  
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> 
<%
   String cubeValue = "six sides";
   pageContext.setAttribute("dimValues", "6");
%>
<html>
<head>
    <title>Testing</title>
    <script type="text/javascript">
        function getDimensions(dim1)
        {
	        document.write(dim1);
        }
    </script>
</head>
<body>
    <div>
    <c:if test='${not empty dimValues}'>
        <script type="text/javascript">
             getDimensions('<%=cubeValue%>');
        </script>
    </c:if>
    </div>
</body>
</html>

Open in new window

0
 

Author Comment

by:Pradip Shenolkar
ID: 40596841
Ok. Hence I'll try to send code in proper format.
I solved the problem.
0
 

Author Closing Comment

by:Pradip Shenolkar
ID: 40596844
Thanks
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
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)

864 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

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now