Wrox Home  
Search P2P Archive for: Go

  Return to Index  

javascript thread: Problem regarding submitting parent form


Message #1 by "Narveer Singh Gahlan" <nsgahlan@e...> on Mon, 24 Sep 2001 14:58:17
Hi All,
I have joined this club today and I have one big problem which i have been 
trying for the past one day.
What I am doing is that I am having a form and I am having a submit button 
which opens a child window.The child window stores a value in the parent 
window in the hidden field.But when I try to submit the form from the child 
window then its not taking the values of the parent window and the i am 
getting null pointer exception as the value for the hidden variables in the 
parent window is null.
And if try to submit the parent form after asigning the value of the hidden 
variable in the child window then My Servlet is not getting executed.Its saying 
that document.forms.submit method is not correct.What should i do now?
What should be my Approach?
I am giving the code of the the parent and child jsp:
<html>
<head>
	<title>Timesheet for the Period </title>
	<link rel=stylesheet type=text/css href=../scripts/unanet2.css 
title="Style Sheet">
	<link rel=stylesheet type=text/css href=../scripts/button.css 
title="Style Sheet">

<SCRIPT language="JavaScript" src="../scripts/TimeSheet.js"></SCRIPT>
<SCRIPT language="JavaScript">

function validateAction(actname)
{
	document.forms[0].actiontype.value=actname;

	if((actname=='save')||(actname=='button')||
(actname=='preview')||(actname=='delete'))
	{
		sendComments();
		document.forms
[0].action='../servlet/com.eforceglobal.tsm.timesheetmgmt.UpdateTimeSheet'
;
	}

	if(actname=='Summary')
	{
	document.forms
[0].action='../servlet/com.eforceglobal.tsm.reports.TSSummary';
	}

	if(actname=='InsertRow')
	{
		sendComments();
		document.forms[0].rowaction.value='InsertRow';
		document.forms
[0].action='../servlet/com.eforceglobal.tsm.timesheetmgmt.TSLineItem';
	}

	if(actname.substring(0,9)=='DeleteRow')
	{
		sendComments();
		document.forms[0].rowaction.value=actname.substring
(0,9);
		document.forms[0].rowid.value=actname.substring(9);
		document.forms
[0].action='../servlet/com.eforceglobal.tsm.timesheetmgmt.TSLineItem';
	}
	

	if(actname=='New_Time_Sheet')
		document.forms[0].action='Open_New_TS.jsp';

	}

</script>
</head>

<body onLoad="setup()">
	<table width=99%>
		<tr>
		<th align=left> </th>		
			<%@ page 
import="com.eforceglobal.tsm.timesheetmgmt.*, javax.naming.*, 
java.sql.*"%>
			<%
        		   	String givendate = null;
				ResultSet rset = null;
				String weekDays[] = new String
[9];
				TimeSheetManager tsm=new 
TimeSheetManager();
				try
				{
					if
((request.getParameter("period")!=null)&&(request.getParameter
("period").equals("current")))
					{
					
						rset = 
tsm.getData("select to_char(sysdate,'mm-dd-yyyy') from dual");
						while
(rset.next())
						{
						
	givendate = rset.getString(1);
						}	
					}
					else
					{
						
						givendate 
= request.getParameter("givendate");
					
	System.out.println("The date is="+givendate);  
					}
					
					weekDays 
=tsm.getWeekDays(givendate);
					}
					
				catch(SQLException se)
				{
				System.out.println("in the catch 
block=");
					se.printStackTrace();
				}
			%>
	</table>
	<form  method="POST" action="" >
		<input type=hidden name=actiontype value="">
		<%
			out.println("<input type=hidden 
name=begindate value="+weekDays[0]+">");
			out.println("<input type=hidden 
name=enddate value="+weekDays[8]+">");
			out.println("<input type=hidden 
name=rowaction value=''>");
			out.println("<input type=hidden 
name=rowid value=''>");
			out.println("<input type=hidden 
name=rowMax value=1>");
			out.println("<input type=hidden 
name=hd_datetotalcomment value=''>");			
		%>
		<input type=hidden name=comments value="">
		<table border=0 cellpadding=1 cellspacing=0>
			<tr bgcolor=lightslategray>
				<th> </th>
				<th colspan=2>Project</th>
				<th>Task</th>
				<th>Activity</th>
				<th>Role</th>
				<%
					out.println("<td 
align=center><strong>Sun</strong><br><small> "+weekDays[1]
+" </small></td>");
					out.println("<td 
align=center><strong>Mon</strong><br><small> "+weekDays[2]
+" </small></td>");
					out.println("<td 
align=center><strong>Tue</strong><br><small> "+weekDays[3]
+" </small></td>");
					out.println("<td 
align=center><strong>Wed</strong><br><small> "+weekDays[4]
+" </small></td>");
					out.println("<td 
align=center><strong>Thu</strong><br><small> "+weekDays[5]
+" </small></td>");
					out.println("<td 
align=center><strong>Fri</strong><br><small> "+weekDays[6]
+" </small></td>");
					out.println("<td 
align=center><strong>Sat</strong><br><small> "+weekDays[7]
+" </small></td>");
				%>
				<th 
bgcolor=lightslategray>Totals</th>
			</tr>
			<tr>
				<td align=center 
bgcolor=lightslategray>
					<!--a 
href="javascript:validateAction('DeleteRow');"><img src=images/delete.gif 
width=16 height=15 alt="Delete row" border=0 align=absmiddle></a-->
					<input type=submit 
onClick="javascript:validateAction(name);" value="X" name=DeleteRow00">
				</td>
				<td colspan=2 nowrap 
align=center bgcolor=lightslategray><select name=dd_proj0000>
						
	<option value="" selected>
							
	<%
		   					
		String uid=(String)session.getAttribute("uid");
		   					
		String username=(String)session.getAttribute
("username");
		   					
		session.putValue("rows","1");
							
		Vector v_project = (Vector)session.getValue
("v_project");
   
   						
	System.out.println("The project vector size ---> "+ v_project.size
());
   							
   						
	for(int count=0; count < v_project.size(); count++)
   						
	{
   							
	System.out.println(v_project.elementAt(count));
   							
	out.println("<option value='"+v_project.elementAt(count)
+"'>"+v_project.elementAt(count)+"</option>");
   						
	}
						
	out.println("<option value=\"E.India-Training\" 
>Training</option>");
						
	out.println("<option value=\"E.India-Authorship\" 
>Authorship</option>");
						
	out.println("<option value=\"E.India-On The Bench\" >On The 
Bench</option>");
						
	out.println("<option value=\"E.India-Out Of Office\" >Out Of 
Office</option>");
						
	out.println("<option value=\"E.India-Sales Support\" >Sales 
Support</option>");
						
	out.println("<option value=\"E.India-Training\" 
>Training</option>");
						
	out.println("<option value=\"E.India-Recruiting Support\" 
>Recruiting Support</option>");

   						
	v_project=null;	
						%>
				</select>

				</td>
				<td bgcolor=lightslategray 
nowrap><select name=dd_task0001>
					<option value="" 
selected>
				<%	
					Vector v_task = 
(Vector)session.getValue("v_task");
					System.out.println
("The task vector size ---> "+ v_task.size());
  						
					for(int count=0; count 
< v_task.size(); count+=2)
					{
						out.println
("<option value='"+v_task.elementAt(count)+"'>"+v_task.elementAt(count+1)
+"</option>");
   					}
   					v_task=null;
					
				%>
			</select>
				</td>
				<td 
bgcolor=lightslategray><select name=dd_acti0002>			
			
					<option value="" 
selected>
					<%
   						Vector 
v_activity = (Vector)session.getValue("v_activity");
					
	System.out.println("The activity vector size ---> "+ v_activity.size
());						
						for(int 
count=0; count < v_activity.size(); count+=2)
						{
   						
	out.println("<option value='"+v_activity.elementAt(count)
+"'>"+v_activity.elementAt(count+1)+"</option>");
   						}
   					
	v_activity=null;
 					%>
					</select>
				</td>
				<td 
bgcolor=lightslategray><select name=dd_role0003>
					<option value="" 
selected>
					<%
						Vector 
v_role = (Vector)session.getValue("v_role");
					
	System.out.println("The role vector size ---> "+ v_role.size());

						for(int 
count=0; count < v_role.size(); count+=2)
						{
						
	out.println("<option value='"+v_role.elementAt(count)
+"'>"+v_role.elementAt(count+1)+"</option>");
						}
					
	v_role=null;
					
	System.out.println("end of New_TimeSheet.jsp");
 					%>
					</select>
				</td>
				<td bgcolor=lightslategray 
align=center><input type=text name=tf_date0004 size=4 maxlength=5 
onChange="dayTotal('tf_date0004', 'tf_t0','tf_rhrs0011',this);" 
onfocus="changeImageOn('00','04',this);" onblur="changeImageOff
('00','04',this);"><br><img src=images/blank.gif name=i_0004 width=20 
height=2 align=top></td>
				<td bgcolor=lightslategray 
align=center><input type=text name=tf_date0005 size=4 maxlength=5 
onChange="dayTotal('tf_date0005', 'tf_t1','tf_rhrs0011',this);" 
onfocus="changeImageOn('00','05',this);" onblur="changeImageOff
('00','05',this);"><br><img src=images/blank.gif name=i_0005 width=20 
height=2 align=top></td>
				<td bgcolor=lightslategray 
align=center><input type=text name=tf_date0006 size=4 maxlength=5 
onChange="dayTotal('tf_date0006', 'tf_t2','tf_rhrs0011',this);" 
onfocus="changeImageOn('00','06',this);" onblur="changeImageOff
('00','06',this);"><br><img src=images/blank.gif name=i_0006 width=20 
height=2 align=top></td>
				<td bgcolor=lightslategray 
align=center><input type=text name=tf_date0007 size=4 maxlength=5 
onChange="dayTotal('tf_date0007', 'tf_t3','tf_rhrs0011',this);" 
onfocus="changeImageOn('00','07',this);" onblur="changeImageOff
('00','07',this);"><br><img src=images/blank.gif name=i_0007 width=20 
height=2 align=top></td>
				<td bgcolor=lightslategray 
align=center><input type=text name=tf_date0008 size=4 maxlength=5 
onChange="dayTotal('tf_date0008', 'tf_t4','tf_rhrs0011',this);" 
onfocus="changeImageOn('00','08',this);" onblur="changeImageOff
('00','08',this);"><br><img src=images/blank.gif name=i_0008 width=20 
height=2 align=top></td>
				<td bgcolor=lightslategray 
align=center><input type=text name=tf_date0009 size=4 maxlength=5 
onChange="dayTotal('tf_date0009', 'tf_t5','tf_rhrs0011',this);" 
onfocus="changeImageOn('00','09',this);" onblur="changeImageOff
('00','09',this);"><br><img src=images/blank.gif name=i_0009 width=20 
height=2 align=top></td>
				<td bgcolor=lightslategray 
align=center><input type=text name=tf_date0010 size=4 maxlength=5 
onChange="dayTotal('tf_date0010', 'tf_t6','tf_rhrs0011',this); " 
onfocus="changeImageOn('00','10',this);" onblur="changeImageOff
('00','10',this);"><br><img src=images/blank.gif name=i_0010 width=20 
height=2 align=top></td>
				<td align=center 
bgcolor=lightslategray><input type=text name=tf_rhrs0011 onfocus=blur() 
size=6></td>
			</tr>
			<tr bgcolor=silver>
				<td align=right><input type=text 
name=addRowNum size=2 maxlength=2 value=1></td><td>
					<!--	<a 
href="javascript:validateAction('InsertRow');"><img src=images/newrow.gif 
width=38 height=19 alt="Insert new row" border=0 align=absmiddle></a> --
>
					<input type=submit 
onClick="javascript:validateAction('InsertRow');" value="InsertRow" 
name=btn_insertrow">
				</td>
				<td align=right></td>
					<th align=right 
colspan=3 > Totals:</th>
				<td align=center><input 
type=text name=tf_t0 size=4 onFocus="blur();"></td>
				<td align=center><input 
type=text name=tf_t1 size=4 onFocus="blur();"></td>
				<td align=center><input 
type=text name=tf_t2 size=4 onFocus="blur();"></td>
				<td align=center><input 
type=text name=tf_t3 size=4 onFocus="blur();"></td>
				<td align=center><input 
type=text name=tf_t4 size=4 onFocus="blur();"></td>
				<td align=center><input 
type=text name=tf_t5 size=4 onFocus="blur();"></td>
				<td align=center><input 
type=text name=tf_t6 size=4 onFocus="blur();"></td>
				<td align=center><input 
type=text name=tf_total size=6 onFocus="blur();"></td>
			</tr>
			<tr>
				<td colspan=5 
valign=top><strong>Status:</strong> 
INUSE<br><strong>Controller:</strong><%out.print(username);%></td>
				<td colspan=7 align=center>
					<table>
						<tr>
						
	<td align=center 
valign=top><strong>Comments:</strong><br><img src=images/red.gif 
width=20 height=2></td>
						
	<td><textarea name=ta_comments cols=30 rows=4 wrap=virtual 
onfocus="addComments();" onblur="removeComments
();"></textarea></td>
						</tr>
					</table>
				</td>
				<td> </td>
			</tr>
			<tr>
				<td colspan=5 valign=top></td>
				<td colspan=7 
align=center></td>
				<td></td>
			</tr>
			<tr>
				<td colspan=5 valign=top></td>
				<td colspan=7 
align=center></td>
				<td></td>
			</tr>
			<tr>
				<td colspan=13 valign=top>
					<input type="submit" 
class="button" value="Save" name="save" onClick="validateAction
(name);">  
					<input type="button" 
class="button" value="Submit" name="submit" onClick="validate();"> 
					<input type="submit" 
class="button" value="Preview" name="preview" onClick="validateAction
(name);">  
					<input type="submit" 
class="button" value="Delete" name="delete" onClick="if(confirm('Are you 
sure you want to delete this Timesheet?')){validateAction(name)};"> 
					<input type="submit" 
class="button" value="New Time Sheet" name="New_Time_Sheet" 
onClick="validateAction(name);"> 
					<input type="submit" 
class="button" value="Summary Report" name="Summary" 
onClick="validateAction(name);">
				</td>
			</tr>
		</table>
	</form>
</body>
</html>



The child jsp is:
<html>
<head>
<title>Submitting Timesheet....</title>
<link rel=stylesheet type=text/css href=../scripts/unanet2.css title="Style 
Sheet">
<link rel=stylesheet type=text/css href=../scripts/button.css title="Style 
Sheet">

<SCRIPT language="JavaScript1.2">

function setComment()
{        
	opener.document.forms
[0].comments.value=document.frm1.comments.value;
        alert("comment value is ===>"+document.frm1.comments.value);
        window.opener.goSubmit();          
 }

</SCRIPT>
</head>
<body bgcolor=#577696>
<form name="frm1" >
<table width=99% height=99%>
<tr>
<td align=center>
<table>
<tr><th align=left valign=top>Timesheet Comments:</th></tr>
<tr><td><textarea name="comments" class="inputwhite" cols="40" 
rows="4" wrap="virtual"></textarea></td></tr>
<tr><td><input type="submit" value=Submit  onClick="setComment(); 
self.close();">
<input type="button" value="Cancel" onClick="window.close()">
</td></tr>
</table>
</td>
</tr>
</table>
</form>
</body>
</html>

  Return to Index