Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript
|
Javascript General Javascript discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 13th, 2006, 11:11 PM
Registered User
 
Join Date: Feb 2006
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default location.replace not working, any ideas?

Hi,

I'm trying to create a confirmation box for deleting a record in a MySQL database. Upon selecting yes I would like to navigate to another page which will run the PHP script. The problem I'm having is that I can't get the browser to redirect upon responding to the confirmation box.

In Firefox it simply stays at the source page(viewevent.php). In IE it redirects me to my index.php regardless of the response.

Code:
    <script language="JavaScript" type="text/JavaScript">        
    function DeleteEvent(id, name)
    {
      var eventid= id;
      var eventname= name;
      var deleteconfirm= confirm("Do you really want to delete event: "+eventid+" - "+eventname+"?");

      if (deleteconfirm== true) {
        window.location.replace("deleteevent.php?eventid="+eventid);
      }
    }
    </script>
If anyone could shed some light on this it would be much appreciated as it's driving me bonkers!

Many Thanks
Swin


 
Old February 14th, 2006, 01:40 AM
Friend of Wrox
 
Join Date: Oct 2004
Posts: 553
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via MSN to vinod_yadav1919 Send a message via Yahoo to vinod_yadav1919
Default

Hii Swin!!

Check whether browser support location.replace or not.
e.g.
You can use following code
<script>
<!--
  var version_val = parseInt(navigator.appVersion)
  //Check whether replace is supported or not
  if (version_val>=4 || window.location.replace)
            window.location.replace("deleteevent.php?eventid=" +eventid);
  else
    window.location.href ="deleteevent.php?eventid="+eventid
// -->
</script>

Hope this will help you


Cheers :)

vinod
 
Old February 14th, 2006, 10:52 AM
Registered User
 
Join Date: Feb 2006
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default

The following code works fine and is identical to yours but deleteevent.php is replaced by http://www.cnn.com.

Therefore I am assuming that deleteevent.php is not located in the same folder as the redirect page?

<script language="JavaScript" type="text/JavaScript">
    function DeleteEvent(id, name)
    {
      var eventid= id;
      var eventname= name;
      var deleteconfirm= confirm("Do you really want to delete event: "+eventid+" - "+eventname+"?");

      if (deleteconfirm== true) {
        window.location.replace("http://www.cnn.com");
      }
    }
 </script>



 
Old February 14th, 2006, 03:35 PM
Registered User
 
Join Date: Feb 2006
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks Kong, but it doesn't redirect even if I use an absolute url for the destination.

The following code is in the head section of a page called viewevent.php:

Code:
    <script language="JavaScript" type="text/JavaScript">        
    function DeleteEvent(id, name)
    {
      var eventid= id;
      var eventname= name;
      var deleteconfirm= confirm("Do you really want to delete event: "+eventid+" - "+eventname+"?");

      if (deleteconfirm== true) {
        window.location.replace("deleteevent.php?eventid="+eventid);
      }
    }
    </script>
The function is triggered by various links further down in the body of the page:

Code:
<td id="link"><a href="" onclick="DeleteEvent('$id','$name')">Delete</a></td>
$id and $name are php variables

The destination deleteevent.php is located within the same directory as viewevent.php.

---

Vinod

I had already tried using window.location, but I did try using your script just to be sure, unfortunately it still didn't solve the problem. I'm using the latest versions of IE and Firefox so that shouldn't be the issue, although it's definitely a good idea for older compatibility.

----

So anyone got any other ideas?

 
Old February 15th, 2006, 06:57 AM
Registered User
 
Join Date: Feb 2006
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Ah ok. I think your problem may be the empty href. Try writing <a href="#">.






Similar Threads
Thread Thread Starter Forum Replies Last Post
parent.location.reload() not working in FireFox AbrarNazeer Javascript 3 February 25th, 2008 05:35 AM
IE7 and parent.location not working? Camer Javascript How-To 2 April 24th, 2007 09:30 AM
PLEASE HELP - I need ideas brettk_1 ASP.NET 1.0 and 1.1 Professional 1 July 13th, 2005 12:42 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.