Problem communicating child/parent values

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • maralfarshadi
    New Member
    • Jul 2007
    • 14

    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,menub ar=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 GetSelectedOpti on(${item[1]})


    Thank you very much for your help
    Maral


    ----------------------------------------------------------------------------------
    [HTML]
    <%@page contentType="te xt/html"%>
    <%@page pageEncoding="U TF-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 GetSelectedOpti on() {

    option1 = ""
    thislen = document.childf 1.CChoice.lengt h;


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

    var str1 = document.childf 1.cbox.value;
    var str2 = document.childf 1.statbox.value ;

    //window.opener.f ocus();

    opener.document .parentf1.getEl ementsByName(st r1).value = option1;
    opener.document .parentf1.getEl ementsByName(st r2).value = 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="Option1Ch oice" value="${item[0]}" onclick="GetSel ectedOption()"/>${item[1]} </td>
    </tr>

    </c:forEach>
    </table>

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

    </form>

    </body>
    </html>[/HTML]
  • gits
    Recognized Expert Moderator Expert
    • May 2007
    • 5390

    #2
    hi ...

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

    kind regards

    Comment

    • maralfarshadi
      New Member
      • Jul 2007
      • 14

      #3
      Originally posted by gits
      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 ?

      Comment

      • gits
        Recognized Expert Moderator Expert
        • May 2007
        • 5390

        #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

        Comment

        • maralfarshadi
          New Member
          • Jul 2007
          • 14

          #5
          Originally posted by gits
          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 GetSelectedOpti on() {

          option1 = "";
          thislen = document.childf 1.CChoice.lengt h;

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

          var str1 = document.childf 1.clmbox.value;
          var str2 = document.childf 1.statbox.value ;

          //window.opener.f ocus();

          opener.document .parentf1.getEl ementsByName(st r1).value = option1;
          opener.document .parentf1.getEl ementsByName(st r2).value = 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="GetSel ectedOption()"/> Some text about France </td></tr>

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

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

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

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

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

          </table>

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

          </form>

          </body>
          </html>[/HTML]

          Comment

          • gits
            Recognized Expert Moderator Expert
            • May 2007
            • 5390

            #6
            hi ...

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

            to your original points:

            3. try

            Code:
            status=yes
            to get the statusbar

            4. try

            Code:
            GetSelectedOption(this.innerHTML);
            to pass the text besides the radiobox ... and your function must receive this of course

            kind regards

            Comment

            • markrawlingson
              Recognized Expert Contributor
              • Aug 2007
              • 346

              #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 :

              [CODE=javascript]
              opener.document .getElementsByN ame(str1).value = option1;
              opener.document .getElementsByN ame(str2).value = option1;
              [/CODE]

              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.

              [CODE=javascript]
              function GetSelectedOpti on() {
              radioObj = document.childf 1.CChoice;
              for (i = 0; i < radioObj.length ; i++) {
              if (radioObj[i].checked) {
              var option1 = radioObj[i].value;
              }
              }
              if (option1 == null) {
              alert("Please choose an option")
              }
              else {
              var str1 = document.childf 1.clmbox.value;
              var str2 = document.childf 1.statbox.value ;
              //window.opener.f ocus();
              top.opener.docu ment.getElement ById(str1).valu e = option1;
              top.opener.docu ment.getElement ById(str2).valu e = option1;
              window.focus();
              window.close();
              }
              }

              [/CODE]

              Comment

              • maralfarshadi
                New Member
                • Jul 2007
                • 14

                #8
                Originally posted by markrawlingson
                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 :

                [CODE=javascript]
                opener.document .getElementsByN ame(str1).value = option1;
                opener.document .getElementsByN ame(str2).value = option1;
                [/CODE]

                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.

                [CODE=javascript]
                function GetSelectedOpti on() {
                radioObj = document.childf 1.CChoice;
                for (i = 0; i < radioObj.length ; i++) {
                if (radioObj[i].checked) {
                var option1 = radioObj[i].value;
                }
                }
                if (option1 == null) {
                alert("Please choose an option")
                }
                else {
                var str1 = document.childf 1.clmbox.value;
                var str2 = document.childf 1.statbox.value ;
                //window.opener.f ocus();
                top.opener.docu ment.getElement ById(str1).valu e = option1;
                top.opener.docu ment.getElement ById(str2).valu e = option1;
                window.focus();
                window.close();
                }
                }

                [/CODE]

                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 :-)

                Comment

                Working...