473,395 Members | 1,488 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Problem communicating child/parent values

Dear All

I am working on a Java based Web app - In this application, a window contains many textboxes which open the same child window. The user should choose among the option boxes provided and the choice should be reported back to parent window.

1. To know which textbox caused the child window to open, the two hidden inputs namely cbox and statbox are used to keep track.

2. The javascript code goes through the option boxes to find which one was chosen. then the value of two hidden textboxes are used to know which parent fileds should be filled with this data.

There is a problem with this code, could you please help me ?? It is not working as expected. The child window opens, but that is it :-(((((

3. Even though I have set (status=1,menubar=1) while opening window , I am not able to see the buttom status bar (I am using IE 6) so I can't really know what line is causing errors ? :-(((

4. How is it possible to transfer the value of text shown beside option box to parent as well ? can I use something like GetSelectedOption(${item[1]})


Thank you very much for your help
Maral


----------------------------------------------------------------------------------
[HTML]
<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title> Displaying choices to the user </title>

<script language="text/javascript">


function GetSelectedOption() {

option1 = ""
thislen = document.childf1.CChoice.length;


for (i = 0; i < thislen; i++) {
if (document.childf1.CChoice[i].checked) {
option1 = document.childf1.CChoice[i].value;
}
}
if (option1 == "") {
alert("Please choose an option")
}
else {

var str1 = document.childf1.cbox.value;
var str2 = document.childf1.statbox.value;

//window.opener.focus();

opener.document.parentf1.getElementsByName(str1).v alue = option1;
opener.document.parentf1.getElementsByName(str2).v alue = option1;


window.focus();
window.close();


}
}

<script>


</head>
<body>


<form method="POST" name="childf1">

<table align="Center" border="0" cellpadding="0"
cellspacing="0" width="80%">

<c:forEach var = "item" items = "${MyArray}">
<tr>
<td> <input type="radio" name="Option1Choice" value="${item[0]}" onclick="GetSelectedOption()"/>${item[1]} </td>
</tr>

</c:forEach>
</table>

<input type="hidden" name="cbox" value="${CBox}" />
<input type="hidden" name="statbox" value="${StatBox}" />
<BR><BR>

</form>

</body>
</html>[/HTML]
Sep 2 '07 #1
7 1650
gits
5,390 Expert Mod 4TB
hi ...

first have a look at your closing </script> tag ...
second change language="text/javascript" to type="text/javascript"

kind regards
Sep 2 '07 #2
hi ...

first have a look at your closing </script> tag ...
second change language="text/javascript" to type="text/javascript"

kind regards
Noted with thanks ......
Any tips to help me solve the problem ?
Sep 2 '07 #3
gits
5,390 Expert Mod 4TB
hi ...

does it work now? ... what errors do you get? please post the code as it turns out in html ... have a look at 'view page source' at the browser ...

kind regards
Sep 2 '07 #4
hi ...

does it work now? ... what errors do you get? please post the code as it turns out in html ... have a look at 'view page source' at the browser ...

kind regards
Unfortunately not yet :-((((
I have included the code generated from view page source. Could you please advise ? I am really confused ... Thanks

By the way apologies for a mistake in first post, when I was preparing the question for forum I made mistake and the name of option box should be CChoice and not Option1Choice. But in the code they had same name.

Best Regards
Maral

The code is :


[HTML]<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>

<script type="text/javascript">
function GetSelectedOption() {

option1 = "";
thislen = document.childf1.CChoice.length;

for (i = 0; i < thislen; i++) {
if (document.childf1.CChoice[i].checked) {
option1 = document.childf1.CChoice[i].value; }
}
if (option1 == "") {
alert("Please choose an option")
}
else {

var str1 = document.childf1.clmbox.value;
var str2 = document.childf1.statbox.value;

//window.opener.focus();

opener.document.parentf1.getElementsByName(str1).v alue = option1;
opener.document.parentf1.getElementsByName(str2).v alue = option1;


window.focus();
window.close(); } }

</script>

</head>
<body>
<form method="POST" name="childf1">
<table align="Center" border="0" cellpadding="0" cellspacing="0" width="80%">

<tr><td> <input type="radio" name="CChoice" value="france" onclick="GetSelectedOption()"/> Some text about France </td></tr>

<tr><td> <input type="radio" name="CChoice" value="germany" onclick="GetSelectedOption()"/> Some text about Germany </td></tr>

<tr> <td> <input type="radio" name="CChoice" value="uk" onclick="GetSelectedOption()"/>Some Text about UK </td></tr>

<tr><td> <input type="radio" name="CChoice" value="China" onclick="GetSelectedOption()"/> Some text about China </td></tr>

<tr><td> <input type="radio" name="CChoice" value="usa" onclick="GetSelectedOption()"/> Some Text about USA </td></tr>

<tr> <td> <input type="radio" name="CChoice" value="japan" onclick="GetSelectedOption()"/> Some text about Japan </td> </tr>

</table>

<input type="hidden" name="clmbox" value="textbox1" />
<input type="hidden" name="statbox" value="hidtextbox1" />
<BR><BR>

</form>

</body>
</html>[/HTML]
Sep 3 '07 #5
gits
5,390 Expert Mod 4TB
hi ...

as far as i can see the code should work? ...

to your original points:

3. try

Expand|Select|Wrap|Line Numbers
  1. status=yes
  2.  
to get the statusbar

4. try

Expand|Select|Wrap|Line Numbers
  1. GetSelectedOption(this.innerHTML);
  2.  
to pass the text besides the radiobox ... and your function must receive this of course

kind regards
Sep 3 '07 #6
markrawlingson
346 Expert 100+
I ran your code

First I recieved an error that stated : opener.document.parentf1... is null or not an object. In response, i removed the 'parentf1' and just left that part of the code as :

Expand|Select|Wrap|Line Numbers
  1. opener.document.getElementsByName(str1).value = option1;
  2. opener.document.getElementsByName(str2).value = option1;
  3.  
I ran the code again and did not recieve an error, subsequently the window closed. However, the two textboxes in the parent window did NOT update. So I changed your code a bit to compensate for it.. and it works perfectly.

Expand|Select|Wrap|Line Numbers
  1.     function GetSelectedOption() {
  2.         radioObj = document.childf1.CChoice;
  3.         for (i = 0; i < radioObj.length; i++) {
  4.             if (radioObj[i].checked) {
  5.                 var option1 = radioObj[i].value;
  6.             }
  7.         }
  8.         if (option1 == null) {
  9.             alert("Please choose an option")
  10.         }
  11.         else {
  12.             var str1 = document.childf1.clmbox.value;
  13.             var str2 = document.childf1.statbox.value;
  14.              //window.opener.focus();
  15.             top.opener.document.getElementById(str1).value = option1;
  16.             top.opener.document.getElementById(str2).value = option1;
  17.             window.focus();
  18.             window.close();
  19.         }
  20.     }
  21.  
  22.  
Sep 3 '07 #7
I ran your code

First I recieved an error that stated : opener.document.parentf1... is null or not an object. In response, i removed the 'parentf1' and just left that part of the code as :

Expand|Select|Wrap|Line Numbers
  1. opener.document.getElementsByName(str1).value = option1;
  2. opener.document.getElementsByName(str2).value = option1;
  3.  
I ran the code again and did not recieve an error, subsequently the window closed. However, the two textboxes in the parent window did NOT update. So I changed your code a bit to compensate for it.. and it works perfectly.

Expand|Select|Wrap|Line Numbers
  1.     function GetSelectedOption() {
  2.         radioObj = document.childf1.CChoice;
  3.         for (i = 0; i < radioObj.length; i++) {
  4.             if (radioObj[i].checked) {
  5.                 var option1 = radioObj[i].value;
  6.             }
  7.         }
  8.         if (option1 == null) {
  9.             alert("Please choose an option")
  10.         }
  11.         else {
  12.             var str1 = document.childf1.clmbox.value;
  13.             var str2 = document.childf1.statbox.value;
  14.              //window.opener.focus();
  15.             top.opener.document.getElementById(str1).value = option1;
  16.             top.opener.document.getElementById(str2).value = option1;
  17.             window.focus();
  18.             window.close();
  19.         }
  20.     }
  21.  
  22.  

Thanks to everyone for their replies and suggestions .... and a special thanks to markrawlingson for taking the time to correct the code.

Have a nice day everybody :-)
Sep 3 '07 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Iain Bishop | last post by:
I'm trying to model objects for the following problem: A building site contains assemblies, each of which can contain other assemblies and/or materials. I have modelled this using a Site...
2
by: Caroline | last post by:
I seem to always want to do this type of join, but I can never find how to do this. I am trying to join two tables. The parent table will always have one row of data and the child may have 0 to...
5
by: Mary Walker | last post by:
Hi, I'm enclosed a snippet of test code which highlights my problem. The Stored procedure insertValue should insert text into the parent, then insert other text into the child table but the 2...
13
by: Stuart McGraw | last post by:
I haven't been able to figure this out and would appreciate some help... I have two tables, both with autonumber primary keys, and linked in a conventional master-child relationship. I've...
6
by: AMeador | last post by:
I have a form where a user will check boxes next to items that have been completed. They will click a button on the form to mark the items as completed. When they do this, I will have the 'parent'...
7
by: Neo Geshel | last post by:
Greetings. I have a serious problem. I have multiple sets of tables, several of which are chained more than two tables deep. That is, I have a parent, a child, and a great-grandchild table. ...
14
by: Lars Netzel | last post by:
A little background: I use three Datagrids that are in a child parent relation. I Use Negative Autoincrement on the the DataTables and that's workning nice. My problem is when I Update these...
1
by: =?Utf-8?B?cmFuZHkxMjAw?= | last post by:
The code below is pretty simple. Calling Talker() in the parent returns "Parent", and calling Talker() in the child returns "Child". I'm wondering how I can modify the code so that a call to the...
1
by: andrewst | last post by:
Originally posted by Divya OK:- SQLcreate table parent( parent_id number primary key, parent_name SQLvarchar2(10) ); Table created. SQLcreate table child( child_id number primary key,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.