How to Populate Fields from New Windows Using JavaScript | HTML Goodies

How to Populate Fields from New Windows Using JavaScript

Jul 3, 2007
3 minute read

It isn’t uncommon for users to have difficulty filling out forms on web
pages. A lot of the time, they need help with filling out various fields with
headings such as: “Where is that number on my check?” “Why
do I need to give you my email address?” “What is a URL?”
These questions and more are usually answered by clicking a little question
mark next to a field, which opens a popup window providing more information
and/or an illustration. In this article, I’ll show you how to enhance
the functionality of these popup windows by allowing the person to fill out
the information there. This will enhance the user experience for a number of
reasons:

  • 1. They don’t have to close the window by clicking that tiny
    little “X” (or circle if they’re on a Mac).
  • 2. They don’t have to remember where they left off before the popup
    opened.
  • 3. They receive help and at the same time, learn what to put into the
    field.

Let’s begin with two documents: a page with a form
and a linked popup window. For this article, I am assuming
you understand the code in the page with a form, which only opens a new window.
If you don’t have this understanding, please take some time to learn
more about opening new windows in JavaScript.
Now, let’s examine
the source of that popup window:

   "http://www.w3.org/TR/html4/strict.dtd">

   
      content="text/html; charset=iso-8859-1">

      JavaScript Example »<br />Filling in Form Values from a New Window.
      
   
   
      

Help

      

Advertisement

Input #1


         

In the input
field labeled "Input #1," please put any information you like. This
is not
      a required field.

      
        

Input
#2


        

Like title="Help on input #1.">input #1, input #2 is not a
required

   field, and you can put any information you want into it.


      
        

Input
#3


        

Input #3 is a required
field. You must select one of the three available options.
        
         

Input
#4

         

Input #4 is a
radio button. You can pick either this one or
you can pick
         title="Help on input #5.">input #5, but you cannot
pick both. This

    field is not required.


         
         

Input
#5


         

Input #5 is a
radio button. Like input #4, you can

    pick either this radio button or
you can pick

          input #4,
but you cannot pick both of them. This field is not required.


         
        
Advertisement

Input
#6


        

Input #6 is a checkbox.
You can click it to check it and click it again to uncheck it. These are used

    for "yes or no" questions, where you can only
choose yes (and check it) or no (and uncheck it).


         
         

Input
#7

         

Input #7 is a
text area. This is a large area where you can type in any text you like. This
field
    is not required.


         
     
   

Let’s take each scenario and analyze it individually. Each form element
has its own function paired with it. This is to easily identify and modify any
code in the future. Let’s begin with input #1.

The JavaScript that is used for all TEXT inputs is:

    function input(formName, obj, val){
      opener.document.forms[formName].elements[obj].value
= val;
      self.close();
    }

 

HTML Goodies Logo

The original home of HTML tutorials. HTMLGoodies is a website dedicated to publishing tutorials that cover every aspect of being a web developer. We cover programming and web development tutorials on languages and technologies such as HTML, JavaScript, and CSS. In addition, our articles cover web frameworks like Angular and React.JS, as well as popular Content Management Systems (CMS) that include WordPress, Drupal, and Joomla. Website development platforms like Shopify, Squarespace, and Wix are also featured. Topics related to solid web design and Internet Marketing also find a home on HTMLGoodies, as we discuss UX/UI Design, Search Engine Optimization (SEO), and web dev best practices.

Property of TechnologyAdvice. © 2026 TechnologyAdvice. All Rights Reserved

Advertiser Disclosure: Some of the products that appear on this site are from companies from which TechnologyAdvice receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. TechnologyAdvice does not include all companies or all types of products available in the marketplace.