Today's Posts Follow Us On Twitter! TFL Members on Twitter  
Forum search: Advanced Search  
Navigation
Marketplace
  Members Login:
Lost password?
  Forum Statistics:
Forum Members: 24,254
Total Threads: 80,792
Total Posts: 566,471
There are 857 users currently browsing (tf).
 
  Our Partners:
 
  TalkFreelance     Design and Development     Programming     PHP and MySQL :

"Are you sure?" button, help, javascript

Thread title: "Are you sure?" button, help, javascript
Closed Thread    
    Thread tools Search this thread Display Modes  
12-23-2006, 01:07 PM
#1
dcb is offline dcb
Status: Junior Member
Join date: Dec 2006
Location: israel
Expertise:
Software:
 
Posts: 27
iTrader: 0 / 0%
 

dcb is on a distinguished road

  Old  "Are you sure?" button, help, javascript

hello, I'm working on a cms for my website and i thought about a little idea
but i don't know how to execute it because i don't know javascript

anyways, i have a delete link, for example:
HTML Code:
<a href="index.php?act=delete&id=100">Delete</a>
clicking this link will send the user to the delete page and do whatever...
i want to make that clicking the link will jump a message asking"Are you sure?",
only if the user selected "yes" it will move on to: index.php?act=delete&id=100

any ideas?

thanks ahead... Daniel

12-23-2006, 01:55 PM
#2
Salathe is offline Salathe
Salathe's Avatar
Status: Community Archaeologist
Join date: Jul 2004
Location: Scotland
Expertise: Software Development
Software: vim, PHP
 
Posts: 3,820
iTrader: 25 / 100%
 

Salathe will become famous soon enough

Send a message via MSN to Salathe

  Old

Code:
onclick="if(!confirm('Are you sure?')) { return false; }"

12-23-2006, 02:38 PM
#3
dcb is offline dcb
Status: Junior Member
Join date: Dec 2006
Location: israel
Expertise:
Software:
 
Posts: 27
iTrader: 0 / 0%
 

dcb is on a distinguished road

  Old

yo thanks allot man

12-24-2006, 12:42 AM
#4
jono1 is offline jono1
jono1's Avatar
Status: Non-conformist
Join date: Jul 2005
Location: Canberra, Australia.
Expertise:
Software:
 
Posts: 1,172
iTrader: 0 / 0%
 

jono1 is on a distinguished road

  Old

It would be more accessible to have a confirmation page within the CMS itself, not using javascript, because users who have javascript disabled, or use screen-reader based browsers (that is, browsers for visually-impaired people) would probably run into problems, and might end up deleting pages without meaning to.

The confirmation page would be pretty simple to incorporate into your CMS - something like:
PHP Code:
if(isset($_GET['confirm'])){
    if(
$_GET['confirm']==true){
        
// Page deletion code here.
    
}
} else {
    echo 
"Are you sure you want to delete this page? This action can not be undone.<br />";
    echo 
"<a href=\"index.php?act=delete&id={$_GET['id']}&confirm=true\">I'm sure.</a> "// {$_GET['id']} inserts the page to delete from the URL of the page you're currently on
    
echo "<a href=\"\">Cancel.</a>"// Point this link to previous page

12-24-2006, 01:59 PM
#5
dcb is offline dcb
Status: Junior Member
Join date: Dec 2006
Location: israel
Expertise:
Software:
 
Posts: 27
iTrader: 0 / 0%
 

dcb is on a distinguished road

  Old

i used a confirm page until now... but it makes the script a lot more longer and not easy to edit...

12-25-2006, 12:00 AM
#6
Joe is offline Joe
Status: Custom User Title
Join date: Apr 2005
Location:
Expertise:
Software:
 
Posts: 2,297
iTrader: 0 / 0%
 

Joe is on a distinguished road

  Old

If the CMS is just for personal use then a Javascript Alert would be fine, but if you plan on distributing it then I reccomend you going for jono1's suggestion and intergrating a confirmation page into the CMS.

12-29-2006, 04:18 PM
#7
Wildhoney is offline Wildhoney
Wildhoney's Avatar
Status: Request a custom title
Join date: Feb 2006
Location: Nottingham
Expertise:
Software:
 
Posts: 1,648
iTrader: 18 / 95%
 

Wildhoney is on a distinguished road

Send a message via AIM to Wildhoney Send a message via MSN to Wildhoney Send a message via Yahoo to Wildhoney

  Old

You should really have a fall back plan in place for if JavaScript is disabled. The best and easiest way to do this is target the relevant event property (onClick) and place Salathe's code onto the button element dynamically, thus if JS is disabled, it'll cruise past it. Ideally to a standard HTML page where you can confirm the deletion.

Code:
<form action="Test/">
	<input type="submit" id="elementName" />
</form>

<script type="text/javascript">

	addEvent(window, 'load', initFunc, false);

	function addEvent(element, eventType, callFunction, useCapture) 
	{
		if(element.addEventListener)
			element.addEventListener(eventType, callFunction, useCapture);
		else if(element.attachEvent)
			element.attachEvent('on'+eventType, callFunction);	
	}

	function initFunc()
	{
		element = document.getElementById('elementName');
		element.onclick = function() { return doConfirm(); };
	}

	function doConfirm()
	{
		var pConfirm = confirm('Delete?');
		if (pConfirm)
			return true;
		return false;
	}

</script>

Closed Thread    


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

  Posting Rules  
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump:
 
  Contains New Posts Forum Contains New Posts   Contains No New Posts Forum Contains No New Posts   A Closed Forum Forum is Closed