jwk811 Posted November 15, 2006 Share Posted November 15, 2006 when i use an alert on a link i want it to either stay there is canceled or go to whereever it was supposed to if clicked ok.. right now either one i click does the same thing.. how can i do this? Quote Link to comment Share on other sites More sharing options...
AndyB Posted November 15, 2006 Share Posted November 15, 2006 An alert? Do you mean a javascript 'confirm'? Sounds like your js is mis-coded. Quote Link to comment Share on other sites More sharing options...
jwk811 Posted November 15, 2006 Author Share Posted November 15, 2006 yes a confim oops.. i dont know what i should put for the true and false.. to continue with the action will be true and to not do that and stay where you are would be false... would you know how to do this? Quote Link to comment Share on other sites More sharing options...
fenway Posted November 16, 2006 Share Posted November 16, 2006 I'm not sure what you mean. Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted November 18, 2006 Share Posted November 18, 2006 When you create the confirmation dialog box using the confirm function you store it in a variable:[code]myConf = confirm('my confirmation message here');[/code]Now the variable myConf will hold the value of true if the user clicks the OK Button, or false if the user clicks the cancel/close button. So to see what button they chose you use a if statement like so:[code]if(myConf) { // TRUE - OK Button} else { // FALSE - Cancel/Close Button}[/code] Quote Link to comment Share on other sites More sharing options...
jwk811 Posted November 18, 2006 Author Share Posted November 18, 2006 so i could just put this at the top of my script?:[code]confirmLogout = confirm('Are you sure you want to logout?');if(confirmLogout){ // TRUE} else { // FALSE}[code]and an onclick="confirmLogout" where i need it?[/code][/code] Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted November 18, 2006 Share Posted November 18, 2006 You'll need to add that code into a function like so:[code]function confirmLogout(){ confirmLogout = confirm('Are you sure you want to logout?'); if(confirmLogout) { return true; } else { return false; }}[/code]Then for your log out link, it'll be like this:[code]<a href="logout.php" onclick="return confirmLogout()">Logout</a>[/code]Now what it will do is if you click the link it'll wait until your press the OK or Cancel button on the confirmation dialogue box that will popup. If you press the Ok button it will then continue on to logout.php or whatever the destination is for the link. If you click the Cancel button or close the confirmation dialogue box it will do nothing and keep you on the same page. Quote Link to comment Share on other sites More sharing options...
jwk811 Posted November 19, 2006 Author Share Posted November 19, 2006 thanks but im getting another problem with that.. when the user clicks logout it shows the pop up but when they click cancel, after that it wont pop up anymore and just go ahead Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.