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

PopUp Causes Form Select Objects to Lose Choices

P: n/a
Hi,
I have a series of Select menus on a page. I am trying to allow the user to
click on the Select title and have it popup a help window. This works fine
with the following code except that all the Select choices are lost.

<A
HREF="javascript:location='menu.jsp';window.open(' menuhelp.jsp?menuID=5','me
nuhelp',)">MenuTitle</A>

I saw an example of a popup on a website that did not lose the menu choices.
This code never calls the javascript function and I can't figure out why. I
know it does not reach the function because it never prints the
out.println("popUp("+page+")");

<A HREF="javascript:popUp('menuhelp.jsp?menuID=5', event)">MenuTitle</A>

function popUp(page,evt){
out.println("popUp("+page+")");
win2 = window.open(page,'pop',"width=400,height=300");
opened = true;
win2.focus();
}

My goal is to get a popup that does not lose my menu choices. Any help is
greatly appreciated.
Thanks,
Mica Cooper

PS. My environment for testing is IE 6.0.2800 with Resin 2.0.3 for my JSP
container on Windows 2000.
Jul 20 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
Lee
Mica said:

Hi,
I have a series of Select menus on a page. I am trying to allow the user to
click on the Select title and have it popup a help window. This works fine
with the following code except that all the Select choices are lost.

<A
HREF="javascript:location='menu.jsp';window.open( 'menuhelp.jsp?menuID=5','me
nuhelp',)">MenuTitle</A>
Don't abuse the javascript: pseudo-protocol like that.
Despite the number of examples you'll find, it's poor practice.
Setting the location attribute is causing your page to reload.

<a href="youShouldEnableJavaScript.html"
onclick="window.open('menuhelp.jsp?menuID=5','menu help');return false">

This code never calls the javascript function and I can't figure out why. I
know it does not reach the function because it never prints the
out.println("popUp("+page+")"); function popUp(page,evt){
out.println("popUp("+page+")");


is out.println() defined as a method in your envirnment?
That's not a standard JavaScript method (JavaScript != Java).

Jul 20 '05 #2

P: n/a
Lee,
Thanks a bunch! I am a server-side Java guy :) You pegged me. What with the
economy and all, the company has got the bright idea that we are experts
with Javascript to. I'll never forget trying to explain the difference to a
director of hiring at a fortune 500.

Your code works...and now I understand why the page was always reloading. I
was wanting to kill the popup when the form unloads. That is why I was
trying a popUp function (and a popDown). Any ideas why it doesn't work? It
does not do a popup at all but redirects to the menuhelp page.

Thanks,
Mica

<A HREF="menuhelp.jsp?menuID=5"
onclick="popUp('menuhelp.jsp?menuID=5',event);retu rn false">
MenuTitle
</A>

function popUp(page,evt){
document.write("inside popUp("+page+")");
xCor=(document.layers)?(screen.width/2):(screen.width/2);
ypos=50;
topPos=ypos;
leftPos=xCor - 300;
details = "width=496,height=305,scrollbars=yes,resizable,lef t=" +
leftPos + ",top=" + topPos;
win2 = window.open(page,'pop',details);
opened = true;
win2.focus();
}
Jul 20 '05 #3

P: n/a
"Mica Cooper" <mi**@aisus.com> writes:
I'll never forget trying to explain the difference to a director of
hiring at a fortune 500.
"You *point* stoopid! Me *bang chest* smart! Here, banana!"
Maybe my negotiation skills need polishing :)
Your code works...and now I understand why the page was always reloading. I
was wanting to kill the popup when the form unloads. That is why I was
trying a popUp function (and a popDown). Any ideas why it doesn't work? It
does not do a popup at all but redirects to the menuhelp page.
The symptoms suggests an error in the Javascript.

If the error is syntactical, the function is never defined (it barfs
during parsing), and it fails when trying to call the non-existing
function. The error need not be in the function itself, it can be anywhere
in the same script element.

If the error is in the function, execution fails during the call to
the function.

In both cases, we never reach "return false", so the href link is
followed.
<A HREF="menuhelp.jsp?menuID=5"
onclick="popUp('menuhelp.jsp?menuID=5',event);retu rn false">
MenuTitle
</A>
I assume some <script type="text/javascript> wrappings around the code
here :)
function popUp(page,evt){
document.write("inside popUp("+page+")");
"document.write" is bad. Unless the document is "open", as while it is
being parsed, writing to it erases the current page.
xCor=(document.layers)?(screen.width/2):(screen.width/2);
var xCor = screen.width/2;

Document.layers is not a foolproof way to recognize Netscape 4.

In general, use local variables (declared with "var") unless you need
the variables to be global. In that case, declare them with "var" outside
the function.
ypos=50;
topPos=ypos;
leftPos=xCor - 300;
Is leftpos perhaps negative after this (probably not, that would
require the screen width to be less than 600, but on very small
screens, it can happen).
details = "width=496,height=305,scrollbars=yes,resizable,lef t=" +
leftPos + ",top=" + topPos;
win2 = window.open(page,'pop',details);
opened = true;
win2.focus();
It should have focus already, but its not an error to be extra certain.
}


I can't see any obvious errors. Maybe it is somewhere in the
surrounding Javascript. Try running the page in Mozilla or Opera and
see if they give an error in the Javascript error console, that might
tell you what the problem is.

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #4

P: n/a
"Mica Cooper" <mi**@aisus.com> wrote in message
news:14******************************@free.teranew s.com...
<snip>
... I am a server-side Java guy :) ... <snip>

Which means that you should be familiar with the logic of this
statement:-
xCor=(document.layers)?(screen.width/2):(screen.width/2);

<snip>

- as it has a direct parallel in Java.

You should be applying the same standards to your JavaScript authoring
as to your Java code. Which means reading and understanding what you
write.

You have also written a function that creates 7 global variables when at
lest 5 of them could be local. You wouldn't give variables more scope
than then need in Java so why do so with JavaScript. The scope
resolution rules may differ but that is no reason for ignoring the
principal.

Richard.
Jul 20 '05 #5

P: n/a
DU
Mica Cooper wrote:
Hi,
I have a series of Select menus on a page. I am trying to allow the user to
click on the Select title and have it popup a help window. This works fine
with the following code except that all the Select choices are lost.

<A
HREF="javascript:location='menu.jsp';window.open(' menuhelp.jsp?menuID=5','me
nuhelp',)">MenuTitle</A>

There should not be any comma at the end of that window.open() call:
either you have a 3rd argument or you don't.
As others mentioned, "javascript:" pseudo-protocol is bad for multiple
reasons and is to be avoided in href values.
I saw an example of a popup on a website that did not lose the menu choices.
This code never calls the javascript function and I can't figure out why. I
know it does not reach the function because it never prints the
out.println("popUp("+page+")");

<A HREF="javascript:popUp('menuhelp.jsp?menuID=5', event)">MenuTitle</A>

function popUp(page,evt){
out.println("popUp("+page+")");
win2 = window.open(page,'pop',"width=400,height=300");
opened = true;
win2.focus();
}

What is the event argument (evt parameter) for in there? If you're
coding for MSIE only, then the window.event object is always accessible,
referencable anyway. If you coding for W3C web standards compliant and
DOM 2 Event compliant browsers, then again, this is not the way to code
a function. In any case, the event argument (evt parameter) serves no
purpose at all in there.
opened = true;
win2.focus();
opened and the focus() call serve no purpose really.

My goal is to get a popup that does not lose my menu choices. Any help is
greatly appreciated.
Thanks,
Mica Cooper

PS. My environment for testing is IE 6.0.2800 with Resin 2.0.3 for my JSP
container on Windows 2000.


DU
--
Javascript and Browser bugs:
http://www10.brinkster.com/doctorunclear/
- Resources, help and tips for Netscape 7.x users and Composer
- Interactive demos on Popup windows, music (audio/midi) in Netscape 7.x
http://www10.brinkster.com/doctorunc...e7Section.html

Jul 20 '05 #6

P: n/a
Thank you!
Error found. This has shown me that my JS Visual Quickstart Guide is
severely lacking. I have the JavaScript Bible and another JS book on order.
I resolve that if I must do JS I'll do it right! :) Now I that I realize JS
has so much power, I'll start migrating server side presentation logic to JS
where appropiate.
Mica

"Lasse Reichstein Nielsen" <lr*@hotpop.com> wrote in message
news:is**********@hotpop.com...
"Mica Cooper" <mi**@aisus.com> writes:
I'll never forget trying to explain the difference to a director of
hiring at a fortune 500.


"You *point* stoopid! Me *bang chest* smart! Here, banana!"
Maybe my negotiation skills need polishing :)
Your code works...and now I understand why the page was always reloading. I was wanting to kill the popup when the form unloads. That is why I was
trying a popUp function (and a popDown). Any ideas why it doesn't work? It does not do a popup at all but redirects to the menuhelp page.


The symptoms suggests an error in the Javascript.

If the error is syntactical, the function is never defined (it barfs
during parsing), and it fails when trying to call the non-existing
function. The error need not be in the function itself, it can be anywhere
in the same script element.

If the error is in the function, execution fails during the call to
the function.

In both cases, we never reach "return false", so the href link is
followed.
<A HREF="menuhelp.jsp?menuID=5"
onclick="popUp('menuhelp.jsp?menuID=5',event);retu rn false">
MenuTitle
</A>


I assume some <script type="text/javascript> wrappings around the code
here :)
function popUp(page,evt){
document.write("inside popUp("+page+")");


"document.write" is bad. Unless the document is "open", as while it is
being parsed, writing to it erases the current page.
xCor=(document.layers)?(screen.width/2):(screen.width/2);


var xCor = screen.width/2;

Document.layers is not a foolproof way to recognize Netscape 4.

In general, use local variables (declared with "var") unless you need
the variables to be global. In that case, declare them with "var" outside
the function.
ypos=50;
topPos=ypos;
leftPos=xCor - 300;


Is leftpos perhaps negative after this (probably not, that would
require the screen width to be less than 600, but on very small
screens, it can happen).
details = "width=496,height=305,scrollbars=yes,resizable,lef t=" +
leftPos + ",top=" + topPos;
win2 = window.open(page,'pop',details);
opened = true;
win2.focus();


It should have focus already, but its not an error to be extra certain.
}


I can't see any obvious errors. Maybe it is somewhere in the
surrounding Javascript. Try running the page in Mozilla or Opera and
see if they give an error in the Javascript error console, that might
tell you what the problem is.

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit.html>
'Faith without judgement merely degrades the spirit divine.'

Jul 20 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.