Home Articles FAQs XREF Games Software Instant Books About Feedback Search Site-Map
irt.org logo

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?

irt.org | Knowledge Base | JavaScript | Window | Q1180 [ previous next ]

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?

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>

Provide feedback ...
AddThis Social Bookmark Button

Provide feedback ... AddThis Social Bookmark Button


Last Updated: 30th March 2008. Maintained by: Martin Webb and Michel Plungjan
irt.org liability, trademark, document use, privacy statement and software licensing rules apply.
Copyright © 1996-2008 irt.org, All Rights Reserved.