Using a popup to fill an input field

Please support our JavaScript / DHTML / AJAX advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Thread Solved

Join Date: May 2004
Posts: 256
Reputation: FireNet will become famous soon enough FireNet will become famous soon enough 
Solved Threads: 6
FireNet's Avatar
FireNet FireNet is offline Offline
Posting Whiz in Training

Using a popup to fill an input field

 
0
  #1
Apr 14th, 2008
Hi,

I am looking for a way to use minimal javascript to open a popup window when the user clicks on an input field and allow them to choose one string inside the pop up window (like click on a radio button) and get the input box in the parent window filled with the value of the string.


I know it's kinda standard, but I dont know much about using javascript ... so I dont know exactly what to search for ....

I've seen hotmail allows you to populate your recipient input box using a popup ... I am looking to do something similar ...
See what you can, remember what you need

Fourzon | Earn via Coding
Reply With Quote Quick reply to this message  
Join Date: Jun 2006
Posts: 7,609
Reputation: ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of 
Solved Threads: 464
Super Moderator
Featured Poster
~s.o.s~'s Avatar
~s.o.s~ ~s.o.s~ is offline Offline
Failure as a human

Re: Using a popup to fill an input field

 
1
  #2
Apr 15th, 2008
An oversimplified example would be:
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. Parent.html
  2.  
  3. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
  4. "http://www.w3.org/TR/html4/strict.dtd">
  5. <html>
  6. <head>
  7. <meta http-equiv"Script-Content-Type" content="text/javascript">
  8. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  9. <meta http-equiv="Expires" content="0"> <!-- disable caching -->
  10. <title>Parent</title>
  11. <script type="text/javascript">
  12. targetElement = null;
  13. function makeSelection(frm, id) {
  14. if(!frm || !id)
  15. return;
  16. targetElement = frm.elements[id];
  17. var handle = window.open('Child.html');
  18. }
  19. </script>
  20. </head>
  21. <body>
  22. <form id="frm" name="frm" action="#">
  23. <span>Name: </span><input name="txtName" id="txtName">
  24. <input type="button" value="Select Name" onclick="makeSelection(this.form, 'txtName');">
  25. </form>
  26. </body>
  27. </html>

JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. Child.html
  2.  
  3. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
  4. "http://www.w3.org/TR/html4/strict.dtd">
  5. <html>
  6. <head>
  7. <meta http-equiv"Script-Content-Type" content="text/javascript">
  8. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  9. <meta http-equiv="Expires" content="0"> <!-- disable caching -->
  10. <title>Example</title>
  11. <script type="text/javascript">
  12. function makeSelection(frm, id) {
  13. if(!frm || !id)
  14. return;
  15. var elem = frm.elements[id];
  16. if(!elem)
  17. return;
  18. var val = elem.options[elem.selectedIndex].value;
  19. opener.targetElement.value = val;
  20. this.close();
  21. }
  22. </script>
  23. </head>
  24. <body>
  25. <form id="frm" name="frm" action="#">
  26. <span>Names: </span>
  27. <select name="nameSelection">
  28. <option value="holly">Holly</option>
  29. <option value="golly">Golly</option>
  30. <option value="molly">Molly</option>
  31. </select>
  32. <input type="button" value="Select Name" onclick="makeSelection(this.form, 'nameSelection');">
  33. </form>
  34. </body>
  35. </html>

The code in itself is self explanatory but feel free to ask for explanations.
I don't accept change; I don't deserve to live.
Reply With Quote Quick reply to this message  
Join Date: May 2004
Posts: 256
Reputation: FireNet will become famous soon enough FireNet will become famous soon enough 
Solved Threads: 6
FireNet's Avatar
FireNet FireNet is offline Offline
Posting Whiz in Training

Re: Using a popup to fill an input field

 
0
  #3
Apr 16th, 2008
Yea, I can see how it works. Thank you.
See what you can, remember what you need

Fourzon | Earn via Coding
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Other Threads in the JavaScript / DHTML / AJAX Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC