• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 249
  • Last Modified:

How do I use javascript to close and then completely refresh the parent window?

I've got a problem with what should be a simple javascript refresh!

I have a table where the user can delete a record. When they select delete, they are presented with a popup confirmation window.

When the user confirms, the record should be deleted (this works perfectly), and the popup window should close (this also works perfectly), and finally the parent window should refresh removing the deleted record from the table.

This is the part that does work. I've tried all sorts of combinations of the following code and I've no idea what I'm doing wrong since the parent seems to refresh a little, but there is no change to the page. If I then refresh manually, the table updates and the deleted record disappears.

Ideas what could be the problem?
<form action="" method="post" name="confirm_delete" target="_parent" id="confirm_delete" onclick="self.close(); window.opener.location.reload();" alt="refresh">
        <label>
        <input type="submit" name="Delete" id="Delete" value="Remove Guest" />
        </label>
        <input name="guestid" type="hidden" id="guestid" value="<?php echo $row_guest_select_remove['guestid']; ?>" />
      </form>

Open in new window

0
beanbaguk2
Asked:
beanbaguk2
  • 4
  • 4
  • 2
2 Solutions
 
quincydudeCommented:
try
parent.opener.location.reload();

btw would it be better if the onclick is triggered on form on submit?
0
 
beanbaguk2Author Commented:
Hi quincydude,

No joy unfortunately. It has the same result as before.

I'm also wondering what you meant by your second statement with regards to the onclick trigger.....

Cheers,

BB
0
 
SreejithGCommented:
//refresh parent window
window.opener.location.reload();
// close self
window.close();
0
Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

 
SreejithGCommented:
The above code shuld be used in the popup page.
0
 
beanbaguk2Author Commented:
Hi again there SreejithG!

Could you elaborate on that please? Should it be in a function?

Cheers,

BB
0
 
SreejithGCommented:
Say you have a button to close the child window. Call the function on click of the button
See the sample below
<HTML>
<HEAD>
<SCRIPT ID=clientEventHandlersJS LANGUAGE=javascript>
<!--
function buttonClose_onclick() 
{
	if(window.opener)
		window.opener.location.reload();
		
	window.close();
}
 
//-->
</SCRIPT>
</HEAD>
<BODY>
<p>
<input type="button" value="Button" id=buttonClose name=buttonClose LANGUAGE=javascript onclick="return buttonClose_onclick()">
</p>
</BODY>
</HTML>

Open in new window

0
 
beanbaguk2Author Commented:
I've done exactly what you mentioned and have the same problem still.

Only this time it takes 2 attempts to remove the record. I've no idea what's going on there......

I need to hit the sack as it's 2:25am here and I've got work at 7am!!!!

I'll catch up with this in the morning.

Cheers,

BB
0
 
quincydudeCommented:
beanbaguk2,

what i meant was not to use onclick but onsubmit

onsubmit="self.close(); window.opener.location.reload();"

as the onclick will be triggered every time the form is being clicked...


0
 
SreejithGCommented:
please provide full page so that I can get more idea on what u r trying
0
 
beanbaguk2Author Commented:
I found an alternative solution. Although what was posted was correct, my circumstances were different and another method was needed. Thanks for the help!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

  • 4
  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now