By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,474 Members | 1,283 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,474 IT Pros & Developers. It's quick & easy.

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

P: 15
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.  
Nov 6 '09 #1
Share this Question
Share on Google+
1 Reply


gits
Expert Mod 5K+
P: 5,390
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
Nov 10 '09 #2

Post your reply

Sign in to post your reply or Sign up for a free account.