PDA

View Full Version : Confirm Issues



Titan85
03-03-2007, 02:42 PM
I am trying to make a script that will send me to a certain page if I click ok or another if I click cancel. This is just a test for another script I am going to use it in, but for some reason none of the javascript is working. Here is the code:
<html>
<head>
<title>Confirm Test</title>
</head>

<body>

<script language="javascript" type="text/javascript">
<!--

var answer = confrim("Are you sure you want to delete")

if(answer) {
window.location = "http://www.google.com";
} else {
window.location = "http://echo-designes.com";
}

//-->
</script>

<a href="javascript:check()">Check</a>
</body>
</html>The confirm box never shows up, but if I throw an alert above it, the alert shows up. Another issue I am having is that whenever I try to make a link to a javascript function, it fails. For example, in one of my scripts I used: <a href="javascript:window.close()">Close Window</a> and it worked fine. Then I turned around and tried to do it in another script and it does not work. I have no idea what is wrong because I literally copied and pasted it to the other script and it won't work. Any ideas. Thanks in advance

jscheuer1
03-03-2007, 03:07 PM
confrim

Spelling counts!

Titan85
03-03-2007, 03:07 PM
Spelling counts!Yes, indeed it does. Can't believe I missed that

Titan85
03-04-2007, 12:56 AM
Ok, I ran into another issue while trying to get it to work in my other script. Now the confirm box shows, but when I click the answer, it doesn't redirect me to the page I specified. Here is the code:
<?php require('../config.php');

@session_start();
if(empty($_SESSION['user']) && empty($_SESSION['pass']) && $_SESSION['ip'] != $_SERVER['REMOTE_ADDR']) {
header('Location: ../login.php');
}

?>
<!--Force IE6 into quirks mode with this comment tag-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Echo CMS | Content Management</title>
<link href="../main-style.css" rel="stylesheet" type="text/css" />

<script language="javascript" type="text/javascript">
<!--
function confDelete() {
var answer = confirm("Are you sure you want to delete selected?");

if(answer) {
window.location = "http://google.com";
} else {
window.location = "http://www.google.com/";
}
}

//-->
</script>

</head>

<body>
<div id="left_frame">
<img src="../images/banner_left.jpg" alt="Echo" />
<div class="innertube">
<div id="user">
<?php require('../left_info.php'); ?>
</div>
<div id="navigation">
<?php
$sql = "SELECT * FROM `navigation` ORDER BY `id` ASC";
$result = mysql_query($sql) or die ('Query Error: <br />' .mysql_error());

while($row = mysql_fetch_array($result)) {
extract($row);
echo '
<div class="nav" onmouseover="this.className=\'nav_hover\'" onmouseout="this.className=\'nav\'"><a href="'.$url.'">'.$title.'</a></div>
';
}
?>
</div>
</div>
</div>
<div id="top_frame">
<img src="../images/banner_right.jpg" alt="CMS" />
</div>
<div id="main_content">
<div class="innertube">
<b>Click Counter Navigation</b>:
<ul>
<li><a href="index.php">Main</a></li>
<li><a href="index.php?act=add">Create New Link</a></li>
</ul>
<!-- PHP Generated Results -->
<?php
if(!$_GET['act'] && !$_POST['delete']) {
echo'
<div class="message">
Use http://echo-designes.com/cms/ccount/clicks.php?id=<b>ID</b> to use each link. Be sure to replace ID with the id of the link.
</div>
<br />
';
require('manage.php');
}
if($_GET['act'] == "add") {
require('add.php');
}

if($_GET['act'] == "edit") {
require('edit.php');
}

if($_GET['act'] == "reset") {
require('reset.php');
}
?>
<!-- /PHP Generated Results -->
</div>
</div>
</body>
</html>Any idea why it doesn't take me to the correct page?

thetestingsite
03-04-2007, 02:36 AM
I don't even see how it calls to the script; but either way, what is it doing? Is it not redirecting to www.google.com or google.com, or is it not redirecting to either? Because http://google.com redirects (gotta be in the A record of their DNS servers or something) to http://www.google.com. Perhaps you are seeing this. Try changing the urls to something different.

Example:

If the user hits "OK", redirect to http://www.google.com, otherwise, go to yahoo.com

Hope this helps.

mburt
03-04-2007, 03:42 AM
if(answer) {
window.location = "http://google.com";
} else {
window.location = "http://www.google.com/";
}
So you're saying if answer returns true - which it already is, because confirm() is always called, even inside a variable - go to http://google.com/. If not go to http://www.google.com/ ? They go to the same site, but that validation is unnecessary since the boolean value is always true.

thetestingsite
03-04-2007, 03:46 AM
Not necessarily (spelling?).



var answer = confirm("Are you sure you want to delete selected?");

if(answer) {


is the same as



if(confirm("Are you sure you want to delete selected?")) {


Either way, the "confirm" box pops up asking "Ok" or "Cancel". So that makes no difference. As said in my previous post, the best way to test it would be to change the urls to different ones.

Titan85
03-04-2007, 04:27 AM
I have tried different urls, then I set them to google to see if they really went anywhere and sure enough, it doesn't redirect. No matter what url I put in, it won't redirect. If I put something else where the window.location is, for example an alert box, the alert box is displayed but for some reason the window.location never works. Any ideas?

jscheuer1
03-04-2007, 06:16 AM
The object - window.location is shorthand for window.location.href. Usually, window.location is fine but, there are many cases when it is not.

One important thing is - is the confirm box popping up? If so, you will fire one of the two boolean branches that depend upon it. If neither is firing, there must be a problem with it (them).

Try window.location.href