Appending Options from Child Windows
As with many others at the site, this script came about as a result of helping someone at one the forums I frequent, The problem was how to append options from a child window to a selection list in the parent window. After pointing out the solution, I decided to play with the script and add a little more functionality. The following tutorial is the result.
Unlike many of the scripts here, this page contains only one function -- OpenWin() -- all of the other code (for selecting the data and creating the selection list options) is located in the child window.
The OpenWin(url) function is nothing special. It simply takes the url as an argument, opens a child window, and then sets focus to it.
In fact, the only interesting thing about the function is the url itself. As you can see from the HTML code below, I appended the formname and selection list name to the document's file name. This was done so that, if wanted, the function could be used with more than one selection list
<input type="button" value="Get Data" onClick="openWin('selPop1.html?mainpage.list1')">
Since the form and selection list names are encoded in the url's location string, the first thing the child window does is parse the location with the location.search property. Note that substr(1) returns only that part of the string after the question mark. The resultant string (in this case: 'mainpage.list1') is then prefixed with the appropriate DOM and eval()ed to create an object with which we can later manipulate.
var selDOM = location.search.substr(1);
The rest of the child window consists of a form with elements and data, and two functions: addSelected() and selectAll(). The former function is activated when the user hits the 'Add Selected Names' button.
<input type="Button" name="Add" value="Add Selected Names" onClick="addSelected(this.form);">
The function itself loops through the child window's form's checkboxes. Once it locates a checked one, it creates a new option for the parent's selection list. Note that I am substr()ing the checkbox's value so that the email address is assigned to the option's value and only the name appears as the option's text.
For a complete discussion of the selectAll() function see the Check Them All But...script/tutorial.
<input type="radio" name="selectall" value="1"
onClick="selectAll(this.form,0);">Select All Names