how to get the value of child window in parent window

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • BibhuAshish
    New Member
    • Oct 2007
    • 34

    how to get the value of child window in parent window

    Hello,
    I have one child window. in child window i am selecting one radio button.
    i want to return that selected value to parent window.
    To open child window in parent window, i have written like this:

    [CODE=javascript]window.open()[/CODE]
    In child window to return a value i have written like this
    child window:

    [CODE=javascript]javascript function
    {
    window.opener.m ozillaval=addfo rm.selection.va lue;
    //also like this
    opener.document .viewform.sourc e=addform.selec tion.value
    }
    [/CODE]But in parent window when i am trying to use the value stored in mozillaval(vari able) i am not getting the value.
    How can i get the child window value in parent window.
    Last edited by gits; Nov 20 '07, 10:24 AM. Reason: added code tags
  • Dasty
    Recognized Expert New Member
    • Nov 2007
    • 101

    #2
    you have to remember the reference to your child window this way:

    Code:
    my_child_window = window.open();
    So from now, you can refer to child window by using my_child_window variable. Like:

    Code:
    alert(my_child_window.document.getElementById('myinput').value);

    Comment

    • trbjr
      New Member
      • Jun 2007
      • 35

      #3
      I am not an expert, but I will tell you what works for me. Because full reference javascript is cumbersome to write, where I have many uses of the values I am saving, I bring the child screen values into an input field in the parent and then in the parent move those to a short-named variable, which I then use in the remainder of my processing.

      I believe you said you were using a radio button in the child screen to capture information and wanted to pass the user selection to the parent screen. Whether or not you use a radio button is irrelevant to the fact that this technique works for all input field types.

      Here is an example of child screen input fields:

      Code:
      <p class="text"> <strong>As a student are you working toward a degree? </strong>&nbsp;&nbsp;
      			<input type="radio" name="degree" value="I am studying for a degree" >YES&nbsp;&nbsp;
      			<input type="radio" name="degree" value="I am not studying for a degree" >NO&nbsp;&nbsp;
      			<input type="radio" name="degree" value="I am not a student" >I am not a student<br>
      First there is a validation phase that verifies what the user responded and moves that response to a variable called wsDegree.

      Code:
       var wsDegree='';
                  function validateResponses() {
      		if	(document.child.degree[0].checked) {
      			wsDegree = document.child.degree[0].value;
      		}
      		if	(document.child.degree[1].checked) {
      			wsDegree = document.child.degree[1].value;
      		}
      		if	(document.child.degree[2].checked) {
      			wsDegree = document.child.degree[2].value;
      		}
                  }
      Then the captured data is moved from the child to the parent:

      Code:
       window.opener.document.parent.pDegree.value = wsDegree;
      In the parent module I have the following corresponding code, which is where the value is placed by the action of the child; the input field is hidden, because I do not want the data to appear on the parent screen - the user does not need to see it there.

      Code:
      <input type="hidden" name="pDegree" maxlength=30 />
      In keeping with my preference to use short variable names rather than long input field names, I have the further step of moving the child field values to a variable in the parent.

      Code:
       var cDegree='';
      cDegree = document.parent.pDegree.value;
      Hope this was what you needed.

      Comment

      • BibhuAshish
        New Member
        • Oct 2007
        • 34

        #4
        Thanks,
        But i wrote the following line in my child window
        window.opener.d ocument.forms[0].address.value = val
        where address is a hidden field.
        the above code is not working.
        but in another page it is working.
        I tried also these lines
        in parent window i did like
        child=window.op en(----);
        document.forms[0].address.value= child.document. val;
        Still it is not working
        can you help me out.

        Comment

        • Estarta
          New Member
          • Nov 2007
          • 1

          #5
          Hey, how are you doing? :)
          well you can use a session
          to save the ClientID for the control you wanna pass the value to " On the parent page"
          like
          Session["txtName"] = txtName.ClientI D;
          and in the child window u may pass whatever you want to this session.

          hope this will help.
          regards

          Comment

          • trbjr
            New Member
            • Jun 2007
            • 35

            #6
            Originally posted by BibhuAshish
            Thanks,
            But i wrote the following line in my child window
            window.opener.d ocument.forms[0].address.value = val
            where address is a hidden field.
            the above code is not working.
            but in another page it is working.
            I tried also these lines
            in parent window i did like
            child=window.op en(----);
            document.forms[0].address.value= child.document. val;
            Still it is not working
            can you help me out.
            Please provide all your code. Show all the relevant parent code separate from all the child code.

            I suggest that you read this forum's help instructions re how to make this forum show your code separately from your comments and questions. The way you present the statement of your problem it is difficult to understand your issue.

            Take care.

            Comment

            Working...