Solved

execute javascript function from jstl <c:if>

Posted on 2015-02-07
3
2,250 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
Comment Utility
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
Comment Utility
Ok. Hence I'll try to send code in proper format.
I solved the problem.
0
 

Author Closing Comment

by:Pradip Shenolkar
Comment Utility
Thanks
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
The viewer will learn how to implement Singleton Design Pattern in Java.
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)

772 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

14 Experts available now in Live!

Get 1:1 Help Now