Link to home
Start Free TrialLog in
Avatar of rotovibe
rotovibe

asked on

Javascript not parsing correctly in JSP page

Can someone help me out with this function?
I get this error when I run it.
I'm only including the script cause that is where the error occurs, I take it out and it works fine.

org.apache.jasper.JasperException: ServletException in '/WEB-INF/jsp/wf-useringroup-assign.jsp': /WEB-INF/jsp/wf-useringroup-assign.jsp(61,28) Element type "x.length" must be followed by either attribute specifications, ">" or "/>".
      org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:476)
      org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:371)
      org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:315)
      org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
      org.apache.struts.action.RequestProcessor.doForward(RequestProcessor.java:1056)
      org.apache.struts.tiles.TilesRequestProcessor.doForward(TilesRequestProcessor.java:261)
      org.apache.struts.tiles.TilesRequestProcessor.processTilesDefinition(TilesRequestProcessor.java:237)
      org.apache.struts.tiles.TilesRequestProcessor.processForwardConfig(TilesRequestProcessor.java:300)
      com.docato.composer.DocatoRequestProcessor.process(DocatoRequestProcessor.java:169)
      org.apache.struts.action.ActionServlet.process(ActionServlet.java:1164)
      org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:397)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:690)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
      com.docato.util.GZIPFilter.doFilter(GZIPFilter.java:40)
      com.docato.util.TidyFilter.doFilter(TidyFilter.java:33)
      com.docato.util.SchematronFilter.doFilter(SchematronFilter.java:131)
      com.docato.util.XSLTFilter.doFilter(XSLTFilter.java:199)
      com.docato.util.SetCharacterEncodingFilter.doFilter(SetCharacterEncodingFilter.java:137)

<script type="text/javascript">
		function submitAction(action)
		{
			document.location.href=action; 	
		}
 
		function onSelectChange()
		{			
		}
 
		function getSelections(btn) 
		{
			var x = document.getElementById('frmMain');
			for (var i=0; i<x.length; i++) 
			{
				if (x[i].type.match(/select/i)) 
				{
					alert(x[i].name);
				}
			}
		}
	</script>

Open in new window

Avatar of Tuno85
Tuno85
Flag of Netherlands image

Did you close the other tags/scriptlets correctly in the rest of your JSP?
Avatar of rotovibe
rotovibe

ASKER

I believe so. I will check again.
All of the tags are closed. I am using JSTL for some dynamic data but it all works fine when I take out the javascript.

The script and the page render fine when I remove the for statement in the script like this:
function getSelections(btn)
{
var x = document.getElementById('frmMain');
[SNIP!!!]
}

It is complaing about the for statement. Mainly the less than sign?
Avatar of Murali Murugesan
your html is not well formed. check for the tag attributes placed without any space between them.

eg:   <table  border="0" class="tborder"width="100%">                                


Should be

<table border="0"  class="tborder" width="100%">                                

I would say a quick way is to change ur .jsp or .html file to .xml and open in a browser to validate the well formedness of ur file.

-Murali*

sorry eg: got mixed up. Here is the correct one

eg:
</table><table  border="0" class="tborder"width="100%">                                

Should be

<table border="0"  class="tborder" width="100%">  
I couldn't find any well-formed type errors.
Attached is the source code. Again, it complains about the for statement in the javascript.
Thanks for the help. I'm pulling my hair out!

<?xml version="1.0" encoding="UTF-8"?>
 
<jsp:root
   xmlns:jsp="http://java.sun.com/JSP/Page"
   xmlns:c="/tags/c"
   xmlns:logic="/tags/struts-logic"
   xmlns:bean="/tags/struts-bean"
   xmlns:html="/tags/struts-html"
   xmlns:tagx="urn:jsptagdir:/WEB-INF/tags"
   xmlns:fn="/tags/functions"
   version="1.2">
<jsp:directive.page import="com.docato.repository.XMLResource"/>
 
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<style type="text/css">
		.dmcstyle {
			text-align: center;
			font-size: small;
		}
		
		.style1 {
			margin-left: 0px;
		}
		
		.gradient {
			background-color: #D9E1E8;
			margin: 0px;
		}
		
		.btn 
		{
			  color:#000000;
			  font: bold 84% 'trebuchet ms',helvetica,sans-serif;
			  background-color:#96A4B4;
			  border: 1px solid;
			  border-color: #696 #363 #363 #696;
			  filter:progid:DXImageTransform.Microsoft.Gradient
			  (GradientType=0,StartColorStr='#ffffffff',EndColorStr='#96A4B4');
			}
						
	</style>
	<script type="text/javascript">
		function submitAction(action)
		{
			document.location.href=action; 	
		}
 
		function onSelectChange()
		{			
		}
 
		function getSelections(btn) 
		{
			var x = document.getElementById('frmMain');
			for (var i=0; i < x.length; i++) 
			{
				if (x[i].type.match(/select/i)) 
				{
					alert(x[i].name);
				}
			}
		}
		
	</script>	
</head>
 
<body>
	<!--<tagx:insert-resource-edit-scripts/>-->
<img style="margin-bottom: -2px;" src="images/activitydetails.jpg"/>
<div class="gradient">
	<form action="CreateDataModule.do" method="post" id="frmMain" name="frmMain">
		<table style="width: 600px;">
			<tr>
				<td colspan="2">
					Please choose a user to assign for each activity.
				</td>
			</tr>
			<tr>
				<td style="border-bottom: #999999 1px solid;" >
					<strong>Activity</strong>
				</td>
				<td style="border-bottom: #999999 1px solid;" >
					<strong>User</strong>	
				</td>
			</tr>
			<c:forEach items="${activities}" var="activity" >
			<tr style="background-color: ${((loop.index % 2) == 0) ? 'whitesmoke' : '#eeeeee'};">
				<td >
					${activity.wfActivityDefinition.activityName}
				</td>
				<td>				
					<select name="${activity.wfActivityDefinition.activityName}" id="${activity.wfActivityDefinition.activityName}" onchange="onSelectChange()">
						<option value="--" >--</option>
						<c:forEach items="${namelist}" var="name">
							<option  value="${name.realName}"  >
								<c:out value="${name.realName}"/>
							</option>
						</c:forEach>
					</select>	
				</td>		
			</tr>		
			</c:forEach>
			<tr>
				<td colspan="2" >
					<button   class="btn" onclick="getSelections(this);">
						<span style="vertical-align: middle;">make assignment</span>
						<img style="vertical-align: middle;"  src="images/accept.png"/>						
					</button>&#160;
				</td>
			</tr>
			<!-- 
			<tr style="border-top : 1px solid #cccccc;">
					<c:forEach items="${nextTrans}" var="trans">
						<td valign="left" style="border: none;"></td>
						<td valign="left" style="border: none;"></td>
					</c:forEach>
			</tr>
			-->
		</table>
	</form>
</div>
<br/>
<br/>
</body>
</html>
 
</jsp:root>

Open in new window

can u try to remove jsp:root tag and map all the tlds as follows, remember to remove the end jsp:root tag as well.

<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>

-Murali*
unfortunately that is an inherited convention. I am making customizations to an existing system that uses that tag declaration format.
Works fine on the other pages. And mine does as well, except when I introduce the "<" sign in that javascript.
ASKER CERTIFIED SOLUTION
Avatar of Tuno85
Tuno85
Flag of Netherlands image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
THAT'S IT!!
The include works perfectly.
Much appreciated!