Web Analytics Made Easy -
StatCounter calling parent window from child, diplaying data line? - CodingForum

Announcement

Collapse
No announcement yet.

calling parent window from child, diplaying data line?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • calling parent window from child, diplaying data line?

    Hey guys.

    Cool forum. I am new to this forum and javascript. I am taking this beginng class and I am almost done with my program but I do not know how to have my child window call the function in the parent.html window. Well I have it call it but I want it to display the data below the buttons of the parentwindow under the line it makes and I do not want the parent window to dissapear and put the data on the new line. I do not know how to display the data values I want..I want to call the function in the parent.html file window by clicking on the child window confirm order. And the have child window dissapear displaying the data in a row below the line and buttons of the first window that popped up. I have no way to understand this. can yu guys give me some good direction. Thank you.







    parent.html

    Code:
    <HTML>
    
    <HEAD>
    
    <TITLE>Parent Window</TITLE>
    
    </HEAD>
    
    <BODY>
    
    <CENTER>
    
    <H2>Robert's Pizza Palace</H2>
    
    <h5>Welcome!</h5>
    
    <HR SIZE=5 WIDTH=90%>
    
    </Center>
    
    <TABLE>
    
    <TD>
    
    </TD>
    
    <TD>
    
    <PRE>
    
    <FORM NAME="OrderForm">
    
    <B>Name:               </B><INPUT TYPE=TEXT NAME="name" ID="name">
    
    <B>Address:            </B><INPUT TYPE=TEXT NAME="address" ID="address">
    
    <B>Phone:              </B><INPUT TYPE=TEXT NAME="phone" ID="phone">
    
    <B>Quantity Ordered:   </B><INPUT TYPE=TEXT NAME="qtypizzas" ID="qtypizzas">
    
    <B></B>
    
    <INPUT type="button" value="Place Order" onClick="window.open('3b.html', 'ConfirmOrder','width=600,height=450')">
    
    <INPUT TYPE="RESET" VALUE="Clear">
    
    </PRE>
    
    </FORM>
    
    </TD>
    
    </TABLE>
    
    <HR SIZE=5 WIDTH=90%> 
    
    <script language="JavaScript">
    
    function DisplayConfirmData()
    
    //this function does not work 
    
    {
    
     window.focus(); 
    
     document.write("Qty" + " + ""Phone"+ " " + "Name");
    
     document.write(QtyPizzas + Phone + Name);
    
    }
    
    </script>
    
    </BODY>
    
    </HTML>


    child.html

    Code:
    <HTML>
    
    <HEAD>
    
    <TITLE>Pizza Order Confirmation</TITLE>
    
    </HEAD>
    
    <BODY>
    
    <CENTER>
    
    <H3>Robert's Pizza Palace!</H3>
    
    <h5>Confirm Your Order Please.</h5>
    
    <h5>Thank You!</h5>
    
    <HR SIZE=5 WIDTH=90%> 
    
    </Center>
    
    <TABLE>
    
    <TD>
    
    </TD>
    
    <TD>
    
    <PRE>
    
    <SCRIPT language="JavaScript"><!--
    
     var Name = window.opener.document.OrderForm.name.value
    
     var Phone = window.opener.document.OrderForm.phone.value
    
     var QtyPizzas = window.opener.document.OrderForm.qtypizzas.value
    
     document.write ("Hello " + Name );
    
     document.write (", You have ordered " + QtyPizzas +  " pizzas.<br>");
    
     document.write ("You will receive a call shortly at " + Phone + ".");
    
    
    
    function CallParentWindowFunction()
    
        {
    
    //trying to pass values back to parent.html while it stays open? 
    
          window.parent.DisplayConfirmData(Name,Phone, QtyPizzas);
    
          window.close();
    
          return false;
    
        }
    
    </SCRIPT>
    
    <INPUT TYPE="BUTTON" NAME="Order" VALUE="Confirm Order"
    
    onclick="javascript:return CallParentWindowFunction();"/>
    
    <INPUT TYPE="BUTTON" VALUE="Cancel"
    
    onclick="window.close()">
    
    </pre>
    
    </table>
    
    </body>
    
    </html>

  • #2
    Well, we aren't going to *DO* your homework for you. Read the general forum rules. We will help with *specific* questions, esp. if you have code that almost but not quite works.

    But you aren't showing *ANY* JavaScript code there, so it's hard for us to correct the non-existent JavaScript code.

    I guess I should ask: How did that child window get created, in the first place? Was it via window.open( ) from the main window? If so, then, yes, you are correct in calling the main window the parent. And so calling a function in it is as easy as referencing it via the keyword parent.
    Be yourself. No one else is as qualified.

    Comment


    • #3
      hey thanks for replying. I never asked you to do my homework.
      why would I display 99% of my work. I just cant seem to reference the parent window and the display data onit by clicking the confirm button
      I made on the child window..The parent window dissappears and yeah I can put data on it but like on a new window. I thought If I posted most of my work maybe i could get help..but thanks anyway.

      Comment


      • #4
        Ah, see...you didn't tell us several important points. For example:
        The parent window dissappears and yeah I can put data on it but like on a new window
        That's undoubtedly because you are using document.write( ). Or, in this case, probably parent.document.write( ).

        You can *NOT* use document.write after an HTML page is complete without, as you have found out, erasing the existing contents and starting the window over again.

        Again, if you had showed us even a smidgen of your JavaScript code, we could have told you that.

        I thought If I posted most of my work maybe i could get help.
        And you might have. But you showed ZERO PERCENT of your JavaScript code, so how can anybody comment on non-existent code? HTML alone is not sufficient.
        Be yourself. No one else is as qualified.

        Comment


        • #5
          Hello sir
          isnt this javascript? I am calling a function in the parent window
          from the child window. So I am here is where I am having the issue.
          Java code calls the function from child to parent window???
          Like I said I am 99 %done. I have javascript code from child window
          call java function within parent. That is my javascript that is the focus. Sams as above code if you
          scroll down you will see this javascript unless all you want to see is the javascript code without HTML?
          if that be case cool then;
          So how much more javascript do I need to be considered javascript? confused here.??? Thanks
          Code:
          <SCRIPT language="JavaScript"><!--
          
           var Name = window.opener.document.OrderForm.name.value
          
           var Phone = window.opener.document.OrderForm.phone.value
          
           var QtyPizzas = window.opener.document.OrderForm.qtypizzas.value
          
           document.write ("Hello " + Name );
          
           document.write (", You have ordered " + QtyPizzas +  " pizzas.<br>");
          
           document.write ("You will receive a call shortly at " + Phone + ".");
          
          
          
          function CallParentWindowFunction()
          
              {
          
          //trying to pass values back to parent.html while it stays open? 
          
                window.parent.DisplayConfirmData(Name,Phone, QtyPizzas);
          
                window.close();
          
                return false;
          
              }

          Comment


          • #6
            THIS IS RIDICULOUS!

            Once again this damned forum deleted one of my posts!

            So I get to do this all again!

            *****************

            First of all, SINCERE APOLOGIES. I do not know WHY, but when I read your first post, I saw *only* the HTML and none of your JS code.

            So no wonder you thought I was nuts! Honest, not nuts. Just BLIND!

            Luckily, I *did* diagnose your problem correctly.

            The culprit is this code:
            Code:
            function DisplayConfirmData()
            {
             window.focus(); 
             document.write("Qty" + " + ""Phone"+ " " + "Name");
             document.write(QtyPizzas + Phone + Name);
            }
            As I said, if you invoke document.write AFTER an HTML page is complete, it WIPES OUT the entire HTML page, even including any JS code on the page.

            But the answer is pretty simple:
            Code:
            function DisplayConfirmData(Name,Phone, QtyPizzas)
            {
                var text = "Confirming that order:<ul>" 
                       + "<li>Name: " + Name + "</li>"
                       + "<li>Phone: " + Phone + "</li>"
                       + "<li>Quantity: " + QtyPizzas + "</li></ul>";
                document.getElementById("CONFIRM").innerHTML = text;
                window.focus( );
            }
            And then just add a <DIV> for that content, perhaps right after your <HR>, thus:
            Code:
            <HR SIZE=5 WIDTH=90%> 
            <DIV ID="CONFIRM" style="font-size: medium;"></DIV>
            Sorry about all that! Will read your posts more carefully next time!
            Be yourself. No one else is as qualified.

            Comment

            Working...
            X