Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Enabling a button

 
Mary Cole
Ranch Hand
Posts: 362
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I have a JSP page and on click of button A , a pop up window opens. When I click on the close button OR when I click on the pop up windows X to close the pop up OR when I click on the parent window, i want to enable a button B on the parent window( note- when I click on the parent window, the pop up automatically closes by itself).
Can anybody tell me how I can achieve this
Thx in advance
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
document.FormName.ButtonName.disabled = false;
 
Mary Cole
Ranch Hand
Posts: 362
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey Eric
How do I handle the situation when the user doesn't close the pop up and simply clicks on the parent window.In this case too the button needs to be enabled(as the pop up closes automatically when i click on the parent window).
What if the user clicks on the browser close icon of the pop up window.How to handle this situation in addition to the above?
Mary
 
Mary Cole
Ranch Hand
Posts: 362
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Guys..pls reply its urgent
 
himanshu patel
Ranch Hand
Posts: 205
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If I understood your problem correctly ,just check below example.
File : main.html
-------------------------
<HTML>
<HEAD>
<SCRIPT LANGUAGE="JavaScript">
function openChildWindow() {
child = window.open('popup.html','myWindow','toolbar=yes,status=yes,scrollbars=yes,location=yes,menubar=yes,directories=yes,width=640,height=480');
}
</SCRIPT>
</HEAD>
<BODY>
<FORM name="parentFrm" >
<INPUT TYPE =button name="ABttn" value="A" event="javascript penChildWindow()"> <br><br>
<INPUT TYPE = button name="BBttn" value="B" DISABLED>
</FORM>
</BODY>
</HTML>
------------------
File : popup.html
<HTML>
<HEAD>
<SCRIPT LANGUAGE="JavaScript">
function enableButton()
{
opener.parentFrm.BBttn.disabled=false;
}
</SCRIPT>
</HEAD>
<BODY onUnload="enableButton()">
<FORM name=childFrm >
<INPUT TYPE = button name="clsBttn" value="Close" event="window.close()">
</FORM>
</BODY>
</HTML>
------------------
Hope this help.
Change word "event" to "onClick".It does not allow me to post if i use "onClick" word inside HTML.
 
Mary Cole
Ranch Hand
Posts: 362
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey himanshu,
Thx for ur reply.
Actually U guys didn't get my point.
2 scenarios are there
1)When the pop up is open and when i click on the pop up windows's close icon(browsers)
, the pop up window closes and automatically the parent windows button should be enabled
2)When the pop up is open, and when i click anywhere on the parent window , the popup should automatically close and enable the parent windows button
I need a script which satisfies these scenarios too

icon
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
himanshu gave you a great starting place. It will enable the button when the child is closed.

 
himanshu patel
Ranch Hand
Posts: 205
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Mary Cole:
Hey himanshu,
Thx for ur reply.
Actually U guys didn't get my point.
2 scenarios are there
1)When the pop up is open and when i click on the pop up windows's close icon(browsers)
, the pop up window closes and automatically the parent windows button should be enabled
2)When the pop up is open, and when i click anywhere on the parent window , the popup should automatically close and enable the parent windows button
I need a script which satisfies these scenarios too
icon

I think you haven't looked carefully at sample code.I am sure it does satisfies your first criteria.
Anyway, try this code and see does it satisfies your all criterias.
-----------------
<HTML>
<HEAD>
<SCRIPT LANGUAGE="JavaScript">
var child;
var flag=1;
function checkFocus(){
if(flag==1){
if (child && !child.closed){
child.close();
parentFrm.BBttn.disabled=false;
}
}else{
flag=1;
}
}
document.onclick = checkFocus;
if (document.captureEvents){
document.captureEvents(Event.CLICK);
}
function openChildWindow() {
child = window.open('popup.htm','myWindow','toolbar=yes,status=yes,scrollbars=yes,location=yes,menubar=yes,directories=yes,width=640,height=480');
}
</SCRIPT>
</HEAD>
<BODY>
<FORM name="parentFrm" >
<INPUT TYPE =button name="ABttn" value="A" onclick="javascript penChildWindow()"> <br><br>
<INPUT TYPE = button name="BBttn" value="B" DISABLED>
</FORM>
</BODY>
</HTML>
---------------------
<HTML>
<HEAD>
<SCRIPT LANGUAGE="JavaScript">
opener.flag=0;
</SCRIPT>
</HEAD>
<BODY onUnload="opener.parentFrm.BBttn.disabled=false;">
<FORM name=childFrm >
<INPUT TYPE = button name="clsBttn" value="Close" onclick="window.close()">
</FORM>
</BODY>
</HTML>
-----------------
 
Mary Cole
Ranch Hand
Posts: 362
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
whats the value which goes to the child variable.... I couldn't see any where how value is assigned to that variable
 
Mary Cole
Ranch Hand
Posts: 362
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sorry i overlooked it..pls ignore my earlier reply
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic