• Post Reply Bookmark Topic Watch Topic
  • New Topic

Getting Values from a window to parent page  RSS feed

 
vjy chin
Ranch Hand
Posts: 279
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am having a jsp page which includes another jsp page. eg


a.jsp includes b. jsp. a.jsp has one form and b.jsp has another form.


a.jsp
-----
<html>

<%@ include file="b.jsp"%>
<form name = aaaaa>

</form>


</html>

b.jsp
-----
<html>
<form name = bbbbb>

</form>

</html>

And in b.jsp I have a icon, its a calendar icon, which on clicking will open a new window (date.jsp page with another form name). What I want is I want to set the date selected from the date.jsp to a.jsp.

I am able to get the values, but the only problem is I am not able to set it to a.jsp.

I am using this function in date.jsp

function getDateFun(year, month, day) {

alert(year);
alert(month);
alert(day);
//alert("dateType: "+dateType);
var vDate = month+"/"+day+"/"+year;

alert("vDate: "+vDate);

window.opener.bbbbb.FromDate.value = vDate;
//parent.opener.FromDate.value = vDate;
window.close();
}


But I am able to get the value updated if the calender image is in the same page, ie in a.jsp. BUt it cannot be like that.

Any help would be of great help.

Thanks
 
Niki Nono
Ranch Hand
Posts: 256
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what you can do is write a javascript function in b.jsp which populates the date values in a.jsp.
you can call this function(of b.jsp) from your date.jsp such as shown below.



Steps done are as follows:
1. b.jsp calls date.jsp
2. date.jsp takes the date and calls the function in b.jsp.
3. write code in b.jsp which will set values in a.jsp using the parent.framename.formname.fieldname.value.

hope this works. let me know.
 
vjy chin
Ranch Hand
Posts: 279
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks dude for your reply. But I was not able to understand as I a still a newbie. Sorry for not being up to your mark.

Actually, I am including the b.jsp in a.jsp. So how will I populate date from b.jsp? Actually in b.jsp only i am showing the date. From there only I am calling the date.jsp, but now its being included in a.jsp. So I think the request to call date.jsp will go from a.jsp. AM I right?

If you want I will give you the whole code of those 3 pages. Please let me know.
Thanks
 
Niki Nono
Ranch Hand
Posts: 256
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
b.jsp is included in a.jsp right?


you have two form elements one for a.jsp and one for b.jsp.

remove the form tag in the page which does not have the text field.
and call the correct form name in date.jsp..


basically you have two forms in your jsp which is not ok. it can have only one form.
take it from here.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66304
152
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
basically you have two forms in your jsp which is not ok. it can have only one form.


Incorrect. You can have as many forms on a page as you wish as long as they have unique names.

What's confusing the OP I feel, is that when you use any of the JSP include mechanisms no parent-child relationship is established. A single monolithic HTML page is still sent to the client regardless of how many JSP includes are performed on the server.

So you need to treat all of the template text in the various JSPs, included or not, as if they are all part of the same HTML page.

So, if all the controls are supposed to act like one big form, there's nothing in the include mechanism to prevent assembling all the controls into a single form.

So the question is: do you really need two forms, or should it all be one?
[ April 15, 2005: Message edited by: Bear Bibeault ]
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I wrote a article on my blog awhile back on transfering data:
http://radio.javaranch.com/pascarello/2005/01/18/1106063002000.html

See if that helps any.

Eric
 
vjy chin
Ranch Hand
Posts: 279
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Thanks for your reply. But I want two forms in a page and the blog also described only for one. But it was great one though.
I am giving the code below.


This is the main jsp. Lets call it a.jsp

a.jsp
=====


<html>
<head>
<title>Create-Booking_Cruise Search</title>
<%@ include file="Header.jsp"%>
<body>

</head>






<td height="8" colspan="4">
<img src="images/empty.gif" width="1" height="1"></td>

<td width="27%" height="19" valign="top"><img src="images/search_details.jpg" width="267" height="19"></td>
<%@ include file="Search.jsp"%>




</form>
</body>
</html>
-------------------------------------------

Search.jsp is as below
======================


<%@ page import="java.text.*,java.util.Date,java.util.*" %>
<body>

<script>
function callDatePicker(strDate){
var url="newDatePicker1.jsp?Date="+strDate;
//alert(url)
window.open(url, "DatePicker", "height=275,width=260,status=yes,titlebar=yes,location=no,toolbar=no,menubar=no,location=no,resizable=no");
}

</script>

<tr>
<td height="0" colspan="4" align="center" bgcolor="#BFDFFF">
<table width="100%" border="0" cellspacing="1" cellpadding="0">
<tr>
<td height="0" bgcolor="#FFFFFF"> <table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="195" height="406" valign="top" bgcolor="#E1F4F7">
<table width="100%" border="0" cellpadding="3" cellspacing="0" class="field">
<tr>
<form name="CreateBookingForm2" method="post" action="a.jsp">

<td class="leftpanetext"><table width="79%" border="0" cellspacing="0" cellpadding="1">
<tr>
<td width="61%" class="leftpanetext">Sail
Date</td>
</tr>
</table></td>
</tr>
<tr>
<td> </td>
</tr>
<tr>
<td valign="top"><table width="65%" border="0" cellspacing="0" cellpadding="1">
<tr>
<td width="15%" class="content"><div align="center">
<p class="fromto">From</p>
</div></td>
<td width="29%">
<input name="FromDate" type="text" class="field" value="" size="15">
</td>
<td width="17%">
<img src="images/calendaropen.gif" width="34" height="21" CallingJavaScriptHere="callDatePicker('FromDate');"></td>
</tr>
</table></td>
</tr>
<tr>
<td valign="top" class="leftpanetext"><table width="65%" border="0" cellspacing="0" cellpadding="1">
<tr>
<td width="15%" class="content"><div align="center">
<p class="fromto">To</p>
</div></td>
<td width="29%">
<input name="ToDate" type="text" class="field" value="" size="15">
</td>
<td width="17%">
<img src="images/calendaropen.gif" width="34" height="21" CallingJavaScriptHere="callDatePicker('ToDate');"></td>
</tr>
</table></td>
</tr>
</form>


--------------------------------------------------------------------------
Here is the newDatePicker.jsp
=============================



<html>
<head>
<script>

function getDateFun(year, month, day) {

//alert(year);
//alert(month);
//alert(day);
//alert("dateType: "+dateType);
var vDate = month+"/"+day+"/"+year;

alert("vDate: "+vDate);

//window.opener.CreateBookingForm2.FromDate.value = vDate;
//window.opener.document.CreateBookingForm2.FromDate.value = vDate;
self.opener.document.CreateBookingForm2.FromDate.value = vDate;
//parent.opener.FromDate.value = vDate;
window.close();
}

</script>
<title>New Date Picker</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<form name="datePicker">

</form>
</body>
</html>

-------------------------------------------------------


Also please note that I have deleted unwanted things and also the alignment might not be proper.

I want the value of the date to be displaed in a.jsp, but the date is really in Search.jsp which is included in a.jsp. Hope I made it clear.

Thanks
 
Niki Nono
Ranch Hand
Posts: 256
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks for pointing out my mistake Bear.
I was under some wrong impressions.
well somethings clear and confirmed now.
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what is the problem with two forms?

document.FormName1.elementName.value = "blah";
document.FormName2.anotherElementName.value = "blah";

pass data back from child window

window.opener.document.FormName1.elementName.value = document.formName.elementName.value;

Eric
 
vjy chin
Ranch Hand
Posts: 279
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your reply Eric, but I couldnt understand it clearly, I am a newbie, so please excuse me.

Actually I am doing the same thing, setting the values from the datePicker.jsp, but I am not able to get it in my parent page, ie a.jsp. I tried setting the values like

window.opener.document.CreateBookingForm2.FromDate.value = vDate;

I also tried setting it like
window.opener.document.cnb2.FromDate.value = vDate; . This is the form name of a.jsp. I know the 2nd one will nt work, since there is exactly no field name called FromDate, but still I tried. But as per what you say Eric, the first one should work, but its not working.


But the same code works search.jsp is not included and there is FromDate field in a.jsp.

Please let me know what to do next.
Thanks for your time and help
 
vjy chin
Ranch Hand
Posts: 279
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am still struggling on this, I couldnt find a solution for this yet. Are there any other ways I can try.
Thanks
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can not have a form inside a form, I think that is what is happening with youur include file.

Eric
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!