Connecting Tech Pros Worldwide Forums | Help | Site Map

How do i get an alert to stop a page from going on

Newbie
 
Join Date: Nov 2008
Posts: 12
#1: 2 Weeks Ago
i have this button, i would like this button on click to pop up an alert "are you sure". If yes continue to the url that in the function, if no stay on the page.

Expand|Select|Wrap|Line Numbers
  1.  
  2. <input type="button" id="addlesson" value="Add Lesson!" onClick="inputter(document.getElementById('testid').value)" />
  3.  
  4.  
here is the inputter function

Expand|Select|Wrap|Line Numbers
  1. function inputter(element){
  2.  
  3.             parent.location='studentaddlesson.php?option=&s_id=' + escape(element);
  4.  
  5.         }
  6.  
  7.             $(document).ready(function() {
  8.  
  9.          $('#testid').keyup(function(e) {
  10.  
  11.         if(!e) e = window.event;
  12.  
  13.         if(e.keyCode == 13) {
  14.             inputter(document.getElementById('testid').value);
  15.         }
  16.          }
  17.  
  18.             )
  19.         } )
  20.  
  21.  
So my question is, how do i tie this jquery alert to the button to stop the action. Right now it pops up but does not stop the page from going to the url


Expand|Select|Wrap|Line Numbers
  1. $(document).ready( function() {
  2.  
  3.                 $("#addlesson").click( function() {
  4.                     jConfirm('Can you confirm this?', 'Confirmation Dialog');
  5.  
  6.                 });
  7.                 });
  8.  
  9.  

gits's Avatar
Moderator
 
Join Date: May 2007
Location: Munich, Germany
Posts: 4,134
#2: 2 Weeks Ago

re: How do i get an alert to stop a page from going on


drop the 'hard-assigned' handler from the button and then do something like this in the onload-handler of the page:

Expand|Select|Wrap|Line Numbers
  1. $(document).ready( function() {
  2.     $("#addlesson").click( function() {
  3.         if ( jConfirm('Can you confirm this?', 'Confirmation Dialog') ) {
  4.             inputter(document.getElementById('testid').value)
  5.         }
  6.     });
  7. });
while i assume that the confirm will return a boolean like it should. which JavaScript framework do you use? JQuery? which version?

kind regards
Reply