Simple JavaScript Code Issue

This is a discussion on Simple JavaScript Code Issue within the Tech Board forums, part of the Community Boards category; I've been through Java, C, C++, and then XHTML. This website's boards are the best help on the web in ...

  1. #1
    Registered User
    Join Date
    Sep 2007
    Location
    Arizona
    Posts
    164

    Simple JavaScript Code Issue

    I've been through Java, C, C++, and then XHTML. This website's boards are the best help on the web in my opinion. The people that helped me with C and C++ were the BEST. I am hoping there are some of you out there that know enough if JavaScript to help me here, too.

    Now I am struggling with this class, it is an online...more like self taught...class and the text book is bad.

    I have four coding assignments left, thank goodness. The one I am working on now is dealing with popup windows and cross-window communication. I have most of it written except for two things. The first is referencing user entered text from the original window in the popup window. The last is writing a line of text in the original window when the popup window is closed.

    If anyone has any ideas I would appreciate the assistance:

    This is 3a.htm (original window)
    Code:
    <html>
    <head>
    <script type='text/javascript'></script>
    </head>
    
    <body>
    <form>
    Name: <input type='text' name='name' /><br><br>
    Phone #: <input type='text' id='cPhone'/><br><br>
    Address: <input type='text' /><br><br>
    How Many Pizzas: <input type='text' id='pOrdered' /><br><br>
    <input type='button' onclick=window.open('3b.htm') value='Order'/>
    </form>
    </body>
    </html>
    and this is 3b.htm (the popup window)
    Code:
    <html>
    <head>
    <script type='text/javascript'>
      var noPizza = document.getElementById('pOrdered');
      var phoneNo = document.getElementById('cPhone');
    </script>
    </head>
    
    <body>
    You have ordered [no of pizza.value here] pizza(s)
    <br>
    You will receive a call shortly at phone number [phone number value here]
    <br><br>
    <input type='button' onclick=window.close() value='Confirm Order' />
    <input type='button' onclick=window.close() value='Cancel' />
    </body>
    </html>
    Thanks!
    Cindy

  2. #2
    Jack of many languages Dino's Avatar
    Join Date
    Nov 2007
    Location
    Katy, Texas
    Posts
    2,309
    If you rewrite 3a.html to dynamically create 3b.html (with document.write), the problem goes away.
    Mac and Windows cross platform programmer. Ruby lover.

    Quote of the Day
    12/20: Mario F.:I never was, am not, and never will be, one to shut up in the face of something I think is fundamentally wrong.

    Amen brother!

  3. #3
    Registered User whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    7,525
    window.opener is another property that solves your problem. You can access 3a.html's named elements through this property.

  4. #4
    Registered User
    Join Date
    Sep 2007
    Location
    Arizona
    Posts
    164
    I did write a function in 3a that created everything I needed in 3b. and I got all excited. Then I couldn't figure out how to get the buttons (confirm order and cancel) to work in that function. AND...the assignment said to create two html pages. So I got discouraged and started all over.

    I have been referencing the information on w3schools website for all the DOM properties and methods. I read and reviewed the opener property but couldn't figure out how to apply it. So, I kept on looking.

    Citizen, if you can' give a little more explanation that would be great.

    Thanks to you both,
    Cindy

  5. #5
    Registered User whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    7,525
    Quote Originally Posted by clegs View Post
    Citizen, if you can' give a little more explanation that would be great.

    Thanks to you both,
    Cindy
    opener is just a reference to the window that opened that window.

    You use it like you would any other:

    Code:
    var pizza = opener.document.getElementById('pOrdered').value
    var phone = opener.document.getElementById('cPhone').value

  6. #6
    Registered User
    Join Date
    Sep 2007
    Location
    Arizona
    Posts
    164
    Thanks!

    I'll try it and see if I can get it to print out.

    Then I have to print a line of text...'Order Submitted'...in 3a when the user clicks the 'Confirm Order' button in 3b. There was a hint to write a function in 3a that displays the message when invoked from the popup. Any ideas on that one?

    I appreciate your help. I have been working on this little bit of code all day. The 'textbook' for the class is 'PPK on JavaScript' he knows his stuff, but for an intro text, is isn't very comprehensive.

    Thanks again!
    Cindy

  7. #7
    Registered User
    Join Date
    Sep 2007
    Location
    Arizona
    Posts
    164
    I got everything to work except writing "Order Submitted" in 3a when the "Confirm Order" button is pushed in 3b.

    I have tried a few things and will keep trying but I am missing the logic on how to make it print.

    Thanks for your help citizen, using "opener" worked perfectly.

    Cindy

  8. #8
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,169
    I believe there's a property window.parent or such that would refer back to the parent window (opener).
    Also, if you open a window, you can store the window, ie:
    var mywindow = open("mywindow.html");

    Now mywindow is that window and you can manipulate it via this variable.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.
    For information on how to enable C++11 on your compiler, look here.
    よく聞くがいい!私は天才だからね! ^_^

  9. #9
    Registered User whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    7,525
    Elysia, variables don't work across pages, FYI. You would need to use function parameters or somesuch.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Simple C++ question. Error in code somewhere.
    By Paracropolis in forum C++ Programming
    Replies: 10
    Last Post: 02-06-2006, 07:59 AM
  2. << !! Posting Code? Read this First !! >>
    By kermi3 in forum Windows Programming
    Replies: 0
    Last Post: 10-14-2002, 01:29 PM
  3. << !! Posting Code? Read this First !! >>
    By kermi3 in forum Game Programming
    Replies: 0
    Last Post: 10-14-2002, 01:27 PM
  4. << !! Posting Code? Read this First !! >>
    By biosx in forum C++ Programming
    Replies: 1
    Last Post: 03-20-2002, 11:51 AM
  5. Simple Code, looking for input.
    By Alien_Freak in forum C Programming
    Replies: 3
    Last Post: 03-03-2002, 10:34 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21