[Javascript] struts form using javascript code
David Lovering
dlovering at gazos.com
Tue Mar 2 18:16:05 CST 2004
Well, aside from some excitingly dreadful formatting, the first "gotchas" I found are in the omission of an include for the driver_new.jsp, the unreferenced object/function attached to the "Delete" key, and the non-displayability of the driverDisplay.do file.
I think perhaps we should try to break this down and address each issue individually, rather than diving in and swimming about in all directions.
Perhaps "Job #1" should be to check that the various necessary browser functions are enabled, and that all the core code modules are within reach. After that, I'd look into each individual module and analyze it from an input/output standpoint, and make sure that it is canonically structured, has a front-end exception filter to remove "bad" inputs, and correctly acts on valid data to produce desired output code.
This is such a bag of worms, I'm not sure where else to start.
-- Dave Lovering
----- Original Message -----
From: Samyukta Akunuru
To: [JavaScript List]
Sent: Tuesday, March 02, 2004 3:52 PM
Subject: Re: [Javascript] struts form using javascript code
Here it is...
Thanks,
Sam.
<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>
<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>
<form name="driversDisplayForm" method="post" action="//deleteDriver.do">
<tr>
<td align="right">
<!-- use onSubmit-- javascript-->
<input type="hidden" name="finalDeleteArray"
value="return getCheckedItems();">
<input type="button" name="Delete" value= "Delete" onClick="getCheckedItems()">
</td>
<td align="right">
<!--html:submit property="submit" value="Add"/-->
<input type="button" name="Add" value= "Add" onClick="window.location.href='driver_new.jsp'">
</td>
</tr>
</table>
<!--html:form action="display" name="displayForm"-->
<table border="1" width="100%">
<tr>
<th><input type=checkbox name="driver_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>
<th><a href="drivers.jsp">Supervisor</a></th>
<th><a href="drivers.jsp">Notes</a></th>
</tr>
<tr align="left">
<td align="center">
<input type=checkbox name="list" value="1">
</td>
<td align="center">
peterson
</td>
<td align="center">
peter
</td>
<td align="center">
j
</td>
<td align="center">
<a href="driverDisplay.do?employeeID=ppeterson">
ppeterson
</a>
</td>
<td align="center">
green, rachel j(rgreen)
</td>
<td align="center">
new addition
</td>
</tr>
</table>
</form>
<SCRIPT LANGUAGE="JavaScript">
function getCheckedItems()
{
var value = false;
menus = new Array;
var msg = "";
var checkBoxes = document.forms[0].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>
Chris Tifer <christ at saeweb.com> wrote:
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
_______________________________________________
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/6a84311d/attachment.htm>
More information about the Javascript
mailing list