Solved

execute javascript function from jstl <c:if>

Posted on 2015-02-07
3
2,662 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

Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

Question has a verified solution.

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

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…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
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…

809 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