See below, The second method may only be executed if the result of the first method is true. Now second method is always being executed. Does someone has a flexible solution? <html> <script type='text/javascript'> function first() { var agree=confirm("Go to second method?"); if (agree) return true ; else return false ; } function second() { var agree=confirm("Are you sure?"); if (agree) return true ; else return false ; } </script> <a href="#" onclick="first();second();return false;">click</a> </html>
Try this. <script type='text/javascript'> function first() { if (confirm("Go to second method?")) { second(); } } function second() { return confirm("Are you sure?"); } </script> Code (javascript): <a href="#" onclick="first(); return false;">click</a> HTML:
As I remember both functions should and will be executed but the return value of the onClick() will cause the browser to navigate to the link in the href or stay in the same page.
Actually I don't want to have a direct reference to the second method in the first, mayby the pseudo code below is explaining a bit more: <html> <script type='text/javascript'> function first(method) { var agree=confirm("Are you sure?"); if (agree) method; } function second() { var agree=confirm("Are you sure2?"); if (agree) return true ; else return false ; } function thirt() { var agree=confirm("Are you sure2?"); if (agree) return true ; else return false ; } </script> <a href="#" onclick="first(second());return false;">KLIK</a> <a href="#" onclick="first(thirt());return false;">KLIK</a> </html>
function check () { if (one()) if (two()) three(); } function one () { return confirm('Are you sure?'); } function two () { return confirm('Are you sure, seriously?'); } function three () { alert('Alright, I understand you are sure!'); } Code (javascript): <a href="#" onclick="check(); return false;">Click me!</a> Code (html4strict): Works for me, test here: www.zelune.com/test/
<a href="#" onclick="if (confirm('Are you sure?')) {if (confirm('Are you sure, seriously?')) {alert('Alright, I understand you are sure!')}}; return false;">Click me!</a> Code (html4strict): Enjoy.