By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,680 Members | 1,475 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,680 IT Pros & Developers. It's quick & easy.

Popup window

P: n/a
Hi,

I want to open a popup-window which displays a list to the user. From this
list, the user can select an item, and the data regarding this item is then
transferred to some fields on the main window (and the popup then closes).

But I am having several problems. I have an example "main.html" which opens
an example "lookup.html". In the actual application "lookup.html" is
generated dynamically be a server, and will have different lists depending
on a "typeid" sent to the server in the request. In the example below I want
the possibility to select from 2 lists: one called FUNCTION, and one called
MATERIAL.

But I can't even get the "function" data to be transferred to the main
window. What is the problem?

Also, what is the easiest way to tell "lookup.html" what fields to write to
on the main window? The field names will be different depending on the
particular list shown (I guess I will need to get the server which generates
the lists to also ensure that the javascript on "lookup.html" matches the
correct field names etc).

Thanks,
Peter

The MAIN window (main.html):

<html>
<head>
<title>
Test Popup
</title>
</head>

<script language="javascript">
function newWindow(url,window,param)
{
popupWindow=open(url, window, param);
if (popupWindow.opener == null) popupWindow.opener = self;
}
</script>

<body>
<table width="100%" border="1" bgcolor="f1f8ff">
<form method="post">
<tr>
<td valign="top" width="20%">
<b>FUNCTION</b>
</td>
<td valign="top" width="40%">
<input type="button" value="pop"
onclick="newWindow('lookup.html?typeid=5000','cata logue','width=500,height=4
00')" />
<input type="hidden" value="2" name="function" />
<input type="text" value="f2" name="function_shortcut"
style="width:25px" />&nbsp;
<input type="text" value="function 2" name="function_name" />
</td>
</tr>
<tr>
<td valign="top" width="20%">
<b>MATERIAL</b>
</td>
<td valign="top" width="40%">
<input type="button" value="pop"
onclick="newWindow('lookup.html?typeid=5001','cata logue','width=500,height=4
00')" />
<input type="hidden" value="11" name="material" />
<input type="text" value="m1" name="material_shortcut"
style="width:25px" />&nbsp;
<input type="text" value="material 1" name="material_name" />
</td>
</tr>
</form>
</table>
</body>
</html>

An example POPUP window (lookup.html):

<html>
<head>
<title>
Lookup
</title>
</head>

<script language="javascript">
function choose( id, shortcut, name )
{
window.opener.document.forms[0].function.value = id;
window.opener.document.forms[0].function_shortcut.value = shortcut;
window.opener.document.forms[0].function_name.value = name;
window.close();
}
</script>

<body>
<table width="100%" border="1" bgcolor="f1f8ff">
<tr>
<td valign="top" width="20%">
<b>Lookup List</b>
</td>
<td>
<table width="100%">
<tr>
<td>
<a href="#" onclick="choose(1,'f1','function 1')">func 1</a>
</td>
</tr>
<tr>
<td>
<a href="#" onclick="choose(2,'f2','function 2')">func 2</a>
</td>
</tr>
<tr>
<td>
<a href="#" onclick="choose(3,'f3','function 3')">func 3</a>
</td>
</tr>
<tr>
<td>
<a href="#" onclick="choose(4,'f4','function 4')">func 4</a>
</td>
</tr>
</table>
</td>
</tr>
</table>
</body>
</html>

Jul 23 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Peter Kirk wrote:
<snip>
<input type="hidden" value="2" name="function" /> ^^^^^^^^ ^^
If you are writing HTML why are there appendix C style XHTML space-slash
sequences at the end of your empty tags?

<snip> <script language="javascript">
function choose( id, shortcut, name )
{
window.opener.document.forms[0].function.value = id;

<snip> ^^^^^^^^

Lowercase "function" is a keyword in javascript and so it cannot be used
as an identifier. Thus it cannot appear in a dot-notation property
accessor (that would be a syntax error). It may be used in a bracket
notation property accessor but changing the name of the INPUT element to
something that does not overlap with known browser property names or
javascript key, or reserved, words would probably be the best idea.

Richard.
Jul 23 '05 #2

P: n/a
Thanks for the quick repsonse...

"Richard Cornford" <Ri*****@litotes.demon.co.uk> skrev i en meddelelse
news:cj*******************@news.demon.co.uk...
Peter Kirk wrote:
<snip>
<input type="hidden" value="2" name="function" /> ^^^^^^^^ ^^
If you are writing HTML why are there appendix C style XHTML space-slash
sequences at the end of your empty tags?


The html I posted were just "exmple" test files. Some of the people I work
with like to put the /> at the end of these sorts of the tags. I thought
that was the "way it was done". I admit my main problem with all this is
that the project I am working on lacks a person who is an expert in
javascript and html. I'm just trying to "hack" the frontend together to hook
it up with the glorious backend code we have written :-) (sorry)

<snip>
<script language="javascript">
function choose( id, shortcut, name )
{
window.opener.document.forms[0].function.value = id;

<snip> ^^^^^^^^

Lowercase "function" is a keyword in javascript and so it cannot be used
as an identifier. Thus it cannot appear in a dot-notation property
accessor (that would be a syntax error). It may be used in a bracket
notation property accessor but changing the name of the INPUT element to
something that does not overlap with known browser property names or
javascript key, or reserved, words would probably be the best idea.


I did wonder if this could be a problem. It appears that an input field
called "function" is ok unless I need to access that field via javascript
(is that the case?). Where can I find information about this "bracket
notation property accessor" you mention. From my point of view it might be
easier to get javascript to write to a field called "function". What about
the "getElementById" function in javascript - would this allow me to access
a field called "function"?

Thanks again,
Peter

Jul 23 '05 #3

P: n/a

"Peter Kirk" <peter> skrev i en meddelelse
news:41********@news.wineasy.se...
Thanks for the quick repsonse...

"Richard Cornford" <Ri*****@litotes.demon.co.uk> skrev i en meddelelse
news:cj*******************@news.demon.co.uk...
Lowercase "function" is a keyword in javascript and so it cannot be used
as an identifier. Thus it cannot appear in a dot-notation property
accessor (that would be a syntax error). It may be used in a bracket
notation property accessor but changing the name of the INPUT element to
something that does not overlap with known browser property names or
javascript key, or reserved, words would probably be the best idea.
I did wonder if this could be a problem. It appears that an input field
called "function" is ok unless I need to access that field via javascript
(is that the case?). Where can I find information about this "bracket
notation property accessor" you mention. From my point of view it might be
easier to get javascript to write to a field called "function". What about
the "getElementById" function in javascript - would this allow me to

access a field called "function"?


Hi, I now have a workable solution. (Good enough for me anyway).
It is indeed possible to use something like this in the popup window:

el = window.opener.document.getElementById('function_id ')

(where el then refers to my main window field called "function", which has
an id "function_id").

Then I can set "el" to the value I want.

Thanks,
Peter

Jul 23 '05 #4

P: n/a
Peter Kirk wrote:
Richard Cornford wrote:
Peter Kirk wrote:
<snip>
> <input type="hidden" value="2" name="function" /> ^^^^^^^^ ^^
If you are writing HTML why are there appendix C style XHTML
space-slash sequences at the end of your empty tags?


The html I posted were just "exmple" test files. Some of the
people I work with like to put the /> at the end of these sorts
of the tags.


They are required if the code is XHTML (except the space as it is only
needed for Appendix C XHTML (which browsers don't regard as XHTML
anyway)). In HTML they are just noise that the browser will
error-correct out. Though apparently they are meaningful in proper SGML,
where the slash would terminate the element and the following '>' would
be lateral and appear in the text. To date nobody has cited a web
browser that follows the SGML rules in this respect so it isn't a
problem, but it is still better not to make the browser waste its time
correcting errors.
I thought that was the "way it was done".
Such nonsense in HTML source code is common, but in web authoring what
is common is not necessarily related to the correct.
I admit my main problem with all this is that the project I am
working on lacks a person who is an expert in javascript and html.
Is there another field of human endeavour where technical jobs are so
routinely handed to individuals without knowledge of the technologies
they are expected to use?
I'm just trying to "hack" the frontend together to hook it up
with the glorious backend code we have written :-) (sorry)
There is no need to apologise, it won't have been you who made the
strange decision.
<snip>
> <script language="javascript">
> function choose( id, shortcut, name )
> {
> window.opener.document.forms[0].function.value = id;

<snip> ^^^^^^^^

Lowercase "function" is a keyword in javascript ...

I did wonder if this could be a problem.
It appears that an input
field called "function" is ok unless I need to access that field via
javascript (is that the case?).
Yes, HTML doesn't care (name attributes are CDATA, virtually
unrestricted) and the server side doesn't have to care either. It still
saves a lot of trouble in the long run if form control names do not
correspond with browser property names, javascript key and reserved
words, etc, and conform to the format of legal javascript identifiers.
Where can I find information about
this "bracket notation property accessor" you mention.
I should be able to say "any book on javascript", but unfortunate that
would not be true as javascript books tend to be poor and the ones I
have read brush over the subject, or make misleading statements about
it. So this group's FAQ is your best bet (and the resources linked to
from it, possibly along with the ECMAScript language specification (ECMA
262 3rd edition):-

<URL: http://jibbering.com/faq >

(quick answers: (4.13) 4.25 and 4.39 directly address this subject.)
From my point of view it might be easier to get
javascript to write to a field called "function".
Bracket notation should allow that.
What about the "getElementById" function in
javascript - would this allow me to access a field called
"function"?


If 'called' means 'given an *ID* attribute of "function"', then yes. But
you sacrifice some back-compatibility in doing so as the -
document.forms - collection (and contained structure) has been around
for considerably longer than W3C DOM Core implementations.

Richard.
Jul 23 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.