www.webdeveloper.com
Page 3 of 3 FirstFirst 123
Results 31 to 36 of 36

Thread: [RESOLVED] Alert box - parsing values

  1. #31
    Join Date
    Jun 2012
    Posts
    48
    Hello again,

    If it only was the old fashion browser alert I wouldn't have started this topic I have such a script but that is the upgly gray browser alert box and that only gives you the option OK in the browsr and not the options YES and NO.
    I wanted a more up-to-date alert box that has colors that suits the colors of the site.

    The page isn't online yet but I'm running it on my local host. If you really want all the files I can send them as attachment in an email to you but therefore I need your email address. You can always send me a pm with your email address. Do not write it here.

    Regards

    PS the onclick code you sent me, also gives an undefined error even when I put the vars in the very beginning of the allert.js script and remove them out of the fuction where they were.

  2. #32
    Join Date
    Aug 2006
    Posts
    301
    i understand that you want to make a pretty alert box, i was saying to display it with a custom function instead of rewriting the normal alert box, so it would still pull up your custom box, but would not change the native alert() code. i'll send you a pm with my email

  3. #33
    Join Date
    Jun 2012
    Posts
    48
    Okay thanks again !!!!

    I just sent you all the files in an email.
    I hope I didn't forget anything ...

    Best regards

  4. #34
    Join Date
    Jun 2012
    Posts
    48
    Give credit where credit is due!!

    Thanks to the excellent help AND a lot of patience of bsmbahamas, my problem has been solved. Hurray !!!

    For those who are interested and who want to use this alert box ...


    in alert.js

    add
    Code:
    var row;"
    remove return false in
    btn.onclick = function() { removeCustomAlert();return false; }
    change function removeCustomAlert() to
    Code:
    function removeCustomAlert(row) {
    	document.getElementsByTagName("body")[0].removeChild(document.getElementById("modalContainer"));
    	window.location='delete.php?do=delete_data&id='+row+'&name='+name;
    }

    in delete.php

    Code:
    <form method="post" action="'.$self.'?do=delete_data&id='.$id.'&name='.$name.'" onclick="alert(\'Delete '.$id.' - '.$name.' ... Are you sure?\');row='.$id.';return false;" >
    and
    Code:
    	case "delete_data";
    
    		if (isset($_GET['id']))
    	{
    		$id = $_GET['id'];
    	}
    	if (isset($_GET['name'])) 
    	{
    		$name = $_GET['name'];
    	}
    
    
    		$data = file($data_file); 
    		$data = array_map('trim',$data); 
    		
    		for ($i=0; $i < count($data); $i++) 
    		{ 
    			$temp = explode(" | ",$data[$i]);
    			
    			if( $temp[0] == $id ){ 
    				unset($data[$i]);
    				$entryName = $temp[1];				
    			} 
    		} 
    		$fp = fopen($data_file,"w");
    		fwrite($fp,implode("\n",$data)); 
    		fclose($fp);
    Regards
    Last edited by coderunner; 06-26-2012 at 01:33 PM.

  5. #35
    Join Date
    Aug 2006
    Posts
    301
    Quote Originally Posted by coderunner View Post
    Give credit where credit is due!!

    Thanks to the excellent help AND a lot of patience of bsmbahamas, my problem has been solved. Hurray !!!
    thanks it was fun.

    one important change is that you should use $_REQUEST instead of GET or POST, if javascript is turned off the data will be sent via POST since the form used method="post" instead of method="get", if javascript is turned on then the form won't submit at all as the custom alert function will block the form submission and instead send the data via GET when it calls window.location,
    so if you use GET or POST instead of REQUEST only the javascript version will work, i.e. if javascript is off, the form will submit via POST and the delete script will ignore the data sent by POST as it is expecting GET, using REQUEST will work in both cases.

    Quote Originally Posted by coderunner View Post
    in delete.php

    Code:
    	case "delete_data";
    
    		if (isset($_REQUEST['id']))
    	{
    		$id = $_REQUEST['id'];
    	}
    	if (isset($_REQUEST['name'])) 
    	{
    		$name = $_REQUEST['name'];
    	}
    
    
    		$data = file($data_file); 
    		$data = array_map('trim',$data); 
    		
    		for ($i=0; $i < count($data); $i++) 
    		{ 
    			$temp = explode(" | ",$data[$i]);
    			
    			if( $temp[0] == $id ){ 
    				unset($data[$i]);
    				$entryName = $temp[1];				
    			} 
    		} 
    		$fp = fopen($data_file,"w");
    		fwrite($fp,implode("\n",$data)); 
    		fclose($fp);
    finally, i'd advise that instead re-writing the native alert() function and using a global variable to instead create a custom function like this...

    function confirmDelete(msg,id){
    /* code goes here */
    }

    ...as this will let you pass the parameters directly to the function instead of using globals, and altering the default alert() functionality.

    cheers

  6. #36
    Join Date
    Jun 2012
    Posts
    48
    Quote Originally Posted by bsmbahamas View Post
    one important change is that you should use $_REQUEST instead of GET or POST, ...
    Oops ... you told me that but I forgot to change that in the code I posted but I used it in my code ...

    Sorry ...

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles