aspose file tools*
The moose likes HTML, CSS and JavaScript and the fly likes Enabling a button Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Enabling a button" Watch "Enabling a button" New topic
Author

Enabling a button

Mary Cole
Ranch Hand

Joined: Dec 02, 2000
Posts: 362
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

Joined: Nov 08, 2001
Posts: 15376
    
    6
document.FormName.ButtonName.disabled = false;
Mary Cole
Ranch Hand

Joined: Dec 02, 2000
Posts: 362
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

Joined: Dec 02, 2000
Posts: 362
Guys..pls reply its urgent
himanshu patel
Ranch Hand

Joined: Feb 03, 2003
Posts: 205
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.


If you want to become a rich, do not work for others but make others to work for you.
Mary Cole
Ranch Hand

Joined: Dec 02, 2000
Posts: 362
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

Joined: Nov 08, 2001
Posts: 15376
    
    6
himanshu gave you a great starting place. It will enable the button when the child is closed.

himanshu patel
Ranch Hand

Joined: Feb 03, 2003
Posts: 205
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

Joined: Dec 02, 2000
Posts: 362
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

Joined: Dec 02, 2000
Posts: 362
sorry i overlooked it..pls ignore my earlier reply
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Enabling a button