• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1262
  • Last Modified:

prompt box in jQuery

Hi,
When a user clicks on a link I want a prompt box to appear asking the if they are sure they want to proceed.  If they click 'OK', they are taken to the destination of the link.  If they click 'Cancel', they remain on the same page.  What is the jQuery syntax for this?

Thanks.
0
deafpanda
Asked:
deafpanda
  • 2
  • 2
1 Solution
 
Tomarse111Commented:
Not sure on jquery syntax but the basic javascript syntax would be
<script type="text/javascript">
	function check(){
		if(confirm('Do you really want to go to this link?')){
			window.location='http://yourlinkhere.com';
		}
	}
</script>
            
<a href="javascript:void(0)" onclick="check();">link</a>

Open in new window

0
 
Tomarse111Commented:
Or even this (but im not sure if this one works in every browser):
<script type="text/javascript">
	function check(){
		if(confirm('Do you really want to go to this link?')){
			return true
		}
		return false
	}
</script>
            
<a href="http://yourlinkhere.com" onclick="return check();">link</a>

Open in new window

0
 
Albert Van HalenCommented:
Have a look at jquery.UI.
There is the dialog which will suit your needs
See this link for some functional demos (http://dev.jquery.com/view/trunk/ui/demos/functional/#ui.dialog)
For documentation see (http://docs.jquery.com/UI/Dialog)
0
 
deafpandaAuthor Commented:
AlbertVanHalen:

Thanks for your advice.  I'm having trouble getting the following code to work - can you tell me where I'm going wrong?  Clicking a link with the id of "delete_entry" should display a dialog box (from a div with id "dialog_delete").  INstead it just acts as a normal link.
$(document).ready(function(){
	('#delete_entry').click(function(){
		$('#dialog_delete').dialog();
		return false;
	});
});

Open in new window

0
 
Albert Van HalenCommented:
You forgot the $ in line 2. Use :  $('#delete_entry').click(function(){
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now