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

rotovibeAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Tuno85Commented:
Did you close the other tags/scriptlets correctly in the rest of your JSP?
0
rotovibeAuthor Commented:
I believe so. I will check again.
0
rotovibeAuthor Commented:
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?
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

Murali MurugesanFull stack Java developerCommented:
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*

0
Murali MurugesanFull stack Java developerCommented:
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%">  
0
rotovibeAuthor Commented:
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

0
Murali MurugesanFull stack Java developerCommented:
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*
0
rotovibeAuthor Commented:
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.
0
Tuno85Commented:
Because you are using the jsp root tag and xml like structure, "<" sign will be seen as opening of the tag causing parsing exceptions.

What happens if you include your javascript code from a .js file.
<script type="text/javascript" src="xxx.js" />

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
rotovibeAuthor Commented:
THAT'S IT!!
The include works perfectly.
Much appreciated!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JSP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.