javascript - Choosing to Continue or Not Continue after Clicking on Link -


i attempting pretty simple: click on link, modal pops continue or cancel link's url, continue url or cancel (essentially hide modal). issue "waiting" period when modal pops up, when user prompted continue or cancel. right now, code never seems run past first waitformodalevent() call:

<a href="someurl" onclick='return handleclick()'> click here </a>     function handleclick() {     if (datachanged()) {         returnvalue = false;         displaymodal();         returnvalue = waitformodalevent();         //never called @ or past point. tested alert()         return returnvalue;     } else {         return true;     }   }    var continueclicked = false;   var cancelclicked = false;   function waitformodalevent() {     while(!continueclicked && !cancelclicked) {         waitformodalevent(); //i know gives browser troubles     }      if (continueclicked) {         return true;     } else {         return false;     }   } 

i know code faulty (especially hideous waitformodalevent() recursive call never ends). however, i'm stuck @ how resolve this, , return true or false in handleclick() after user clicks on either continue or cancel. setup using <a href>'s onclick inherently bad setup i'm trying accomplish?

i've read on callbacks, can't grasp how use callbacks situation (if any). appreciate sort of suggestions or insight!

you've generated infinite loop locks javascript event loop. until while loop finished variables testing in can never changed.

if want based on dom based dialogue, have callbacks. there no way (outside of host environment provided function confirm) block while waiting user interaction.

the general approach using callbacks here always cancel default action of clicking link, , have callback replicate functionality (or put regular link in dialogue).


Comments

Popular posts from this blog

1111. appearing after print sequence - php -

java - WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/board/] in DispatcherServlet with name 'appServlet' -

Ruby on Rails, ActiveRecord, Postgres, UTF-8 and ASCII-8BIT encodings -