By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,377 Members | 1,722 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,377 IT Pros & Developers. It's quick & easy.

Popup value returned to parent window

100+
P: 384
I have a page that has this code that opens a popup winodw, I need the value thats clicked on to be added to the span on the parent page, can anyone help? Also if you click something from the popup window and something already exists in the span it will append the new value to the exist value in the span?

I greatly appreciate any help here, thanks.

Parent page:
Expand|Select|Wrap|Line Numbers
  1. <a href="#" onClick="targetitem = document.forms[0].related;dataitem = window.open('popup2.php','dataitem','width=200, height=100, top=10, left=300');dataitem.targetitem = targetitem">add</a> <label name="related"></label>
Popup page:
Expand|Select|Wrap|Line Numbers
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"  "http://www.w3.org/TR/html4/loose.dtd">
  2. <html>
  3. <head>
  4. <title>Javascript(Popup 2)</title>
  5. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 
  6. <script>
  7. function select_item(item) {
  8.     targetitem.value = item;
  9.     top.close();
  10.     return false;
  11. }
  12. </script>
  13. </head>
  14. <body>
  15. <label onClick='return select_item("1");'>test 1</label>
  16. </body>
  17. </html>
May 26 '11 #1

✓ answered by ziycon

Got it, i needed to use getElementById instead of getElementsByName.

Share this Question
Share on Google+
2 Replies


100+
P: 384
I've gotten to the stage where I'm not getting any JS errors but I can't get the popup box value to append to the label on the parent page, can anyone point me in the right direction please?

Parent:
Expand|Select|Wrap|Line Numbers
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"  "http://www.w3.org/TR/html4/loose.dtd">
  2. <html>
  3. <head>
  4. <title>Javascript(Popup)</title>
  5. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 
  6. </head>
  7. <body>
  8. <form>
  9. <a href="#" onClick="targetitem = document.getElementsByName('related');dataitem = window.open('popup2.php','dataitem','width=200, height=100, top=10, left=300');dataitem.targetitem = targetitem">add</a>
  10. <label name="related"></label>
  11. </form>
  12.  
  13. </body>
  14. </html>
Popup:
Expand|Select|Wrap|Line Numbers
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"  "http://www.w3.org/TR/html4/loose.dtd">
  2. <html>
  3. <head>
  4. <title>Javascript(Popup 2)</title>
  5. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 
  6. <script>
  7. function select_item(item) {
  8.     targetitem.innerHTML = item;
  9.     top.close();
  10.     return false;
  11. }
  12. </script>
  13.  
  14. </head>
  15. <body>
  16. <label onClick='return select_item("1");'>test 1</label><br/>
  17. <label onClick='return select_item("2");'>test 2</label>
  18. </body>
  19. </html>
May 27 '11 #2

100+
P: 384
Got it, i needed to use getElementById instead of getElementsByName.
May 27 '11 #3

Post your reply

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