Results 1 to 13 of 13

Thread: How do I populate a form field from another window?

  1. #1
    Join Date
    Apr 2005

    How do I populate a form field from another window?

    Here's my scenario:

    Main Window:
    I have a field called Zipcode
    There is a link that opens a new window which enables me to search for zip codes.

    ZipCode Window:
    I can enter the name of a city and a list of zip codes show up.

    Here's what I want:
    I want to be able to click on the zip code which was found in the ZipCode Window and have that number be automatically populated in the Zipcode field which is in the Main Window

    Any help greatly appreciated!

  2. #2
    Join Date
    Jul 2004
    Canada, eh
    let's say you have
    <form name="zipform" action="nextpage.php" method="post">
    <input name="zipcode" id="zipcode" type="text">
    in your main window.

    In the popup window, you would have links like
    <a href="#" onclick="window.opener.document.getElementById('zipcode').value='12345';window.close();">12345</a>
    The forum has put some spaces in that shouldn't be there in v alue
    Kids, kids... you tried your best, and you failed miserably; the lesson is: never try.

  3. #3
    Join Date
    Apr 2005
    Hey great thanks! This is working good There's only one snag...I failed to state that there will be 3 zip code fields in the main window. I need to be able to fill them in independantly using this feature.

    I'm using PHP

    What do you reccomend?

    Last edited by jaytee; 04-15-2005 at 01:25 AM.

  4. #4
    Join Date
    Apr 2005
    Wow, this forum moves fast! Anyways, just gonna ask another time before this post gets lost in ether

    So how would I go about populating 3 different zip code fields independantly?

    Thanks alot...any help greatly appreciated!

  5. #5
    Join Date
    Jul 2004
    Canada, eh
    Sorry I'm not at your beck and call. I had to go to bed last night and then I had to go to work this morning. Now it's lunch time.

    You would give each form field a unique id (zipcode1, zipcode2, zipcode3) and then (I'm assuming you open the window for one and make the selection, then open it for the next one, etc) you could have the id be a querystring variable passed to the popup window and use it to determine which form field gets the value

    Main window, revised
    <form name="zipform" action="nextpage.php" method="post">
    <p><input name="zipcode1" id="zipcode1" type="text"> <a href="popup.php?fieldId=zipcode1" target="_blank">Choose from a list</a></p>
    <p><input name="zipcode2" id="zipcode2" type="text"> <a href="popup.php?fieldId=zipcode2" target="_blank">Choose from a list</a></p>
    <p><input name="zipcode3" id="zipcode3" type="text"> <a href="popup.php?fieldId=zipcode3" target="_blank">Choose from a list</a></p>
    Popup window, revised
    <a href="#" onclick="window.opener.document.getElementById('<?php echo $_GET["fieldId"]; ?>').value='12345';window.close();">12345</a>
    Kids, kids... you tried your best, and you failed miserably; the lesson is: never try.

  6. #6
    Join Date
    Apr 2005

    Thumbs up

    Hey, I hope I didn't come off as an ass I'm just new to this forum and didn't realize how quickly things move around here and was affraid it was going to get lost. I'm sorry for the misunderstanding

    Anyways, thank you very very very much for your help! You are a code wizard


  7. #7
    Join Date
    Jul 2004
    Canada, eh
    Don't worry, I was only kidding
    Kids, kids... you tried your best, and you failed miserably; the lesson is: never try.

  8. #8
    Join Date
    Apr 2005
    Oh and HaganeNoKokoro, you thought it was over? No!! Haha. Anyways, was wondering howi can get the zipcode finder window to open a new window at a fixed size and positioned in the center of the screen. I tried using DreamWeavers Open Window behavior, but it screws up the code and doesnt work.

    Anyways, any help greatly appreciated (again)

  9. #9
    Join Date
    Jul 2004
    Canada, eh
    for that, you will need a function like
    <script type="text/javascript">
    function popup(url, x, y, w, h) {
      var params="x="+x+", y="+y+", width="+width+", height="+height;
      window.open(url, "_blank", params);
    And then the links that open the windows will be like
    <a href="#" onclick="popup('popup.php?fieldId=zipcode1', 100, 100, 200, 400);return false;">Choose from a list</a>
    Of course you will have to change the x, y, w, and h to suit where you want the window and how big. I don't know if there's a way to make it appear in the exact center of the screen, although you could use screen.width and screen.height to calculate it.
    Kids, kids... you tried your best, and you failed miserably; the lesson is: never try.

  10. #10
    Join Date
    Apr 2005
    Wow thanks man! This is great but..............

    You're really going to hate me now!!

    I found the ultimate way that I would like for this to work. Instead of clicking "Find This Zip" for all 3 fields, you can just click these checkboxes and do all 3 at once.

    Please check out this perfect example here:

    That's EXACTLY what I want. But I don't think I can just lift the code from that site. Do you know of any similar ways of working it? Any idears?


  11. #11
    Join Date
    Jul 2004
    Canada, eh
    For that you will need something like this
    <script type="text/javascript">
    function submitForm(frm) {
      var cur=1;
      for(var i=0; i<frm.elements.length; i++) {
        if(frm.elements[i].type=="checkbox") {
          if(frm.elements[i].checked) {
          if(cur>4) break; //put the number of fields you want fileld here
    in the popup window. The form in the popup will also need a button
    <input type="button" onclick="submitForm(this.form)">
    for the user to click when they're done.

    If you also want the "You can only select 4 zipcodes" message to pop up, youo will need to add an onclick handler to the checkboxes. put this function
    function validate(frm) {
      var cnt=0;
      for(var i=0; i<frm.elements.length; i++) {
        if(frm.elements[i].type=="checkbox"&&frm.elements[i].checked) cnt++;
        if(cnt>4) {
          alert("You can only select 4 zipcodes");
    with the other one, and have checkboxes like this
    <input type="checkbox" name="somezip" value="12345" onclick="validate(this.form)">
    I haven't tested out any of this so there will probably be problems.
    Last edited by HaganeNoKokoro; 04-21-2005 at 11:14 PM.
    Kids, kids... you tried your best, and you failed miserably; the lesson is: never try.

  12. #12
    Join Date
    Apr 2005
    Holy crap! You are amazing! I'm gonna have to give this a try tomorrow. Thanks a billion! I'll let you know if I got it to work.
    Thanks again!

  13. #13
    Join Date
    May 2003
    Last edited by shawjames; 08-10-2012 at 11:41 AM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center



X vBulletin 4.2.2 Debug Information

  • Page Generation 0.12101 seconds
  • Memory Usage 2,981KB
  • Queries Executed 15 (?)
More Information
Template Usage (33):
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_global_above_footer
  • (1)ad_global_below_navbar
  • (1)ad_global_header1
  • (1)ad_global_header2
  • (1)ad_navbar_below
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (1)ad_thread_first_post_content
  • (1)ad_thread_last_post_content
  • (10)bbcode_code
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)headinclude_bottom
  • (13)memberaction_dropdown
  • (1)navbar
  • (4)navbar_link
  • (1)navbar_moderation
  • (1)navbar_noticebit
  • (1)navbar_tabs
  • (2)option
  • (13)postbit
  • (13)postbit_onlinestatus
  • (13)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available (6):
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files (26):
  • ./showthread.php
  • ./global.php
  • ./includes/class_bootstrap.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/functions_navigation.php
  • ./includes/class_friendly_url.php
  • ./includes/class_hook.php
  • ./includes/class_bootstrap_framework.php
  • ./vb/vb.php
  • ./vb/phrase.php
  • ./includes/functions_facebook.php
  • ./includes/functions_calendar.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_notice.php
  • ./packages/vbattach/attach.php
  • ./vb/types.php
  • ./vb/cache.php
  • ./vb/cache/db.php
  • ./vb/cache/observer/db.php
  • ./vb/cache/observer.php 

Hooks Called (70):
  • init_startup
  • friendlyurl_resolve_class
  • init_startup_session_setup_start
  • database_pre_fetch_array
  • database_post_fetch_array
  • init_startup_session_setup_complete
  • global_bootstrap_init_start
  • global_bootstrap_init_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • load_show_variables
  • load_forum_show_variables
  • global_state_check
  • global_bootstrap_complete
  • global_start
  • style_fetch
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • strip_bbcode
  • friendlyurl_clean_fragment
  • friendlyurl_geturl
  • forumjump
  • cache_templates
  • cache_templates_process
  • template_register_var
  • template_render_output
  • fetch_template_start
  • fetch_template_complete
  • parse_templates
  • fetch_musername
  • notices_check_start
  • notices_noticebit
  • process_templates_complete
  • friendlyurl_redirect_canonical
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • memberaction_dropdown
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • build_navigation_data
  • build_navigation_array
  • check_navigation_permission
  • process_navigation_links_start
  • process_navigation_links_complete
  • set_navigation_menu_element
  • build_navigation_menudata
  • build_navigation_listdata
  • build_navigation_list
  • set_navigation_tab_main
  • set_navigation_tab_fallback
  • navigation_tab_complete
  • fb_like_button
  • showthread_complete
  • page_templates