Home Articles FAQs XREF Games Software Instant Books BBS About FOLDOC RFCs Feedback Sitemap
irt.Org
#

Q1180 If I have a list A-Z, how can I open a popup window which contains a list of words beginning with the letter chosen, that when clicked place the word in a search form filed back on the original window?

You are here: irt.org | FAQ | JavaScript | Window | Q1180 [ previous next ]

Try:

<script language="JavaScript"><!--
var windowHandle = null;

function openPopup(letter) {
    windowHandle = window.open('about:blank','windowName','width=300,height=300');
    setTimeout('updatePopup("' + letter + '")',1);
}

function updatePopup(letter) {
    var output = '';
    if (letter == 'A') {
        output = formatList('ant','antelope','apple','axe');
    }
    if (letter == 'B') {
        output = formatList('ball','bee','belt','box');
    }
    // ...
    if (letter == 'Z') {
        output = formatList('zebra','zoo','zulu');
    }
    windowHandle.document.open();
    windowHandle.document.write(output);
    windowHandle.document.close();
}

function formatList() {
    var output = '<ul>';
    for (var i=0; i<arguments.length; i++) {
        output+='<li><a href="javascript:close()" onClick="opener.document.myForm.search.value=\'' + arguments[i] + '\'">' + arguments[i] + '<\/a><\/li>';
    }
    output += '<\/ul>';
    return output;
}
//--></script>

<a href="javascript:openPopup('A')">A</a>
<a href="javascript:openPopup('B')">B</a>
...
<a href="javascript:openPopup('Z')">Z</a>

<form name="myForm">
<input type="text" name="search">
</form>

©2018 Martin Webb