473,224 Members | 1,736 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,224 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 1643
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,...
1
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
0
by: veera ravala | last post by:
ServiceNow is a powerful cloud-based platform that offers a wide range of services to help organizations manage their workflows, operations, and IT services more efficiently. At its core, ServiceNow...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
2
by: jimatqsi | last post by:
The boss wants the word "CONFIDENTIAL" overlaying certain reports. He wants it large, slanted across the page, on every page, very light gray, outlined letters, not block letters. I thought Word Art...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....

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.