Results 1 to 9 of 9

Thread: Confirm Issues

  1. #1
    Join Date
    Aug 2006
    Location
    Ohio
    Posts
    266
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Confirm Issues

    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 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
    Thanks DD, you saved me countless times

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    confrim
    Spelling counts!
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. #3
    Join Date
    Aug 2006
    Location
    Ohio
    Posts
    266
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by jscheuer1 View Post
    Spelling counts!
    Yes, indeed it does. Can't believe I missed that
    Thanks DD, you saved me countless times

  4. #4
    Join Date
    Aug 2006
    Location
    Ohio
    Posts
    266
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    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:
    HTML 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?
    Thanks DD, you saved me countless times

  5. #5
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    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.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  6. #6
    Join Date
    Jul 2006
    Location
    Canada
    Posts
    2,581
    Thanks
    13
    Thanked 28 Times in 28 Posts

    Default

    Code:
    		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.
    - Mike

  7. #7
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    Not necessarily (spelling?).

    Code:
    var answer = confirm("Are you sure you want to delete selected?");
    
    		if(answer) {
    is the same as

    Code:
    		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.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  8. #8
    Join Date
    Aug 2006
    Location
    Ohio
    Posts
    266
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    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?
    Thanks DD, you saved me countless times

  9. #9
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    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
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •