468,766 Members | 1,305 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,766 developers. It's quick & easy.

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 1448
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

Post your reply

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

Similar topics

6 posts views Thread by Iain Bishop | last post: by
5 posts views Thread by Mary Walker | last post: by
6 posts views Thread by AMeador | last post: by
7 posts views Thread by Neo Geshel | last post: by
1 post views Thread by =?Utf-8?B?cmFuZHkxMjAw?= | last post: by
1 post views Thread by andrewst | last post: by
reply views Thread by Marin | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.