[Javascript] struts form using javascript code
Chris Tifer
christ at saeweb.com
Tue Mar 2 12:32:33 CST 2004
Show us the final code that gets sent to the browser.
----- Original Message -----
From: Samyukta Akunuru
To: [JavaScript List]
Sent: Tuesday, March 02, 2004 1:24 PM
Subject: Re: [Javascript] struts form using javascript code
Chris,
Thanks for the reply.
"And after looking a little closer, I don't even see a <form> element so maybe that's your problem." ---------> Yes struts was going to generate the <form> element after the jsp was compiled using jasper.
Has anyone used struts with javascript...
Thanks.
Chris Tifer <christ at saeweb.com> wrote:
My best guess by looking at that and your brief description is that the field parameter being passed into the check() function is not a field as it expects, but rather a pointer to a form object. form.length is not a property, but forms.length is.
And after looking a little closer, I don't even see a <form> element so maybe that's your problem.
Chris Tifer
----- Original Message -----
From: Samyukta Akunuru
To: javascript at laTech.edu
Sent: Tuesday, March 02, 2004 9:32 AM
Subject: [Javascript] struts form using javascript code
Hi
Code below gives me :form.length is null or not an object.
Any tips appreciated.
Tahns
<%@ page language="java"%>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<html>
<head>
<style><!--
body,td,a,p,.h{font-family:times new roman,arial,sans-serif;}
.h{font-size: 20px;}
.q{text-decoration:none; color:#0000cc;}
//-->
</style>
<% com.dynetics.gmpm.rad.Principal pl = (com.dynetics.gmpm.rad.Principal) session.getAttribute("principal");
if(pl != null)System.out.println("*** principal is not null");
if(pl == null) {
%>
<jsp:forward page="logout.jsp"/>
<%
}
com.dynetics.gmpm.rad.PrincipalHolder.setPrincipal(pl);
%>
<SCRIPT LANGUAGE="JavaScript">
var checkflag = "false";
function check(field) {
if (checkflag == "false") {
for (i = 0; i < field.length; i++) {
field[i].checked = true;}
checkflag = "true";
return "Uncheck All"; }
else {
for (i = 0; i < field.length; i++) {
field[i].checked = false; }
checkflag = "false";
return "Check All"; }
}
function set(target) {document.forms[0].dispatch.value=target;}
</script>
</head>
<body>
<table border="0" width="100%">
<tr>
<td bgcolor="00007D" align="center">
<font color=white size="6"><b><u>Drivers</u></b></font>
</td>
</tr>
</table>
<table>
<tr>
<td align="right">
<input type="hidden" name="finalDeleteArray"
value="return getCheckedItems();">
<input type="button" name="Delete" value= "Delete" onClick="getCheckedItems()">
</td>
<td align="right">
<a href="driver_new.jsp" target="frame_main"><input type="button" name="Add" value= "Add" onClick="window.location.href='driver_new.jsp'"></a>
</td>
</tr>
</table>
<html:form action="display" name="displayForm" type="com.servlet.DisplayForm" >
<table border="1" width="100%">
<tr>
<th><input type=checkbox name="d_all" value="Check All" onClick="check(this.form.list)"></th>
<th><a href="drivers.jsp">Last name</a></th>
<th><a href="drivers.jsp">First Name</a></th>
<th><a href="drivers.jsp">Middle Name</a></th>
<th><a href="drivers.jsp">Clock #</a></th>
</tr>
<tr align="left">
<td align="center"><!--input type=checkbox name="list"-->
<input type=checkbox name="list" value="0">
</td>
<td align="center">
Smith
</td>
<td align="center">
Ashley
</td>
<td align="center">
K
</td>
<td align="center">
<a href="driverDisplay.do?employeeID=asmith">
asmith
</a>
</td>
<td align="center">
</td>
<td align="center">
new driver
</td>
</tr>
<tr align="left">
<td align="center"><!--input type=checkbox name="list"-->
<input type=checkbox name="list" value="1">
</td>
<td align="center">
David
</td>
<td align="center">
John
</td>
<td align="center">
V
</td>
<td align="center">
<a href="driverDisplay.do?employeeID=jdavid">
jdavid
</a>
</td>
<td align="center">
</td>
<td align="center">
Novice
</td>
</tr>
<tr align="left">
<td align="center"><!--input type=checkbox name="list"-->
<input type=checkbox name="list" value="2">
</td>
<td align="center">
Doe
</td>
<td align="center">
John
</td>
<td align="center">
K
</td>
<td align="center">
<a href="driverDisplay.do?employeeID=jdoe">
jdoe
</a>
</td>
<td align="center">
Doe, John K(jdoe)
</td>
<td align="center">
novice
</td>
</tr>
</table>
</html:form>
<SCRIPT LANGUAGE="JavaScript">
function getCheckedItems()
{
var value = false;
menus = new Array;
var msg = "";
var checkBoxes = driversDisplayForm.elements["list"];
for(var i = 0; i < checkBoxes.length; i++)
{
if(checkBoxes[i].checked)
{
menus = menus+","+i;
value = true;
}
}
menusChopped = menus.substr(1,menus.length-1);//chop leading comma
deleteArray = new Array;
deleteArray = menusChopped.split(",");
finalDeleteArray = new Array;
for (i=0;i<deleteArray.length;i++){
finalDeleteArray[i]= deleteArray[i];
alert(finalDeleteArray[i]);
}
if(!value)
alert("Check at least one of the checkboxes, thanks.");
//this.form.action="http://myserver.com/searchById/submit.do";//fix this
//window.location.href='deleteDriver.do';
return finalDeleteArray;
}
</script>
</body>
</html>
--------------------------------------------------------------------------
Do you Yahoo!?
Yahoo! Search - Find what you're looking for faster.
--------------------------------------------------------------------------
_______________________________________________
Javascript mailing list
Javascript at LaTech.edu
https://lists.LaTech.edu/mailman/listinfo/javascript
_______________________________________________
Javascript mailing list
Javascript at LaTech.edu
https://lists.LaTech.edu/mailman/listinfo/javascript
------------------------------------------------------------------------------
Do you Yahoo!?
Yahoo! Search - Find what you're looking for faster.
------------------------------------------------------------------------------
_______________________________________________
Javascript mailing list
Javascript at LaTech.edu
https://lists.LaTech.edu/mailman/listinfo/javascript
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.evolt.org/pipermail/javascript/attachments/20040302/65d1f135/attachment.htm>
More information about the Javascript
mailing list