jaymc Posted November 6, 2006 Share Posted November 6, 2006 I have the following code...[code]OnClick="return confirmblock(); window.location='http://google.co.uk';"[/code]The problem is, regardless of the [b]confirmblock();[/b] outcome which is [b]ok/cancel[/b] window.location still goes ahead and executesNow I have a fealing the space between [b]return confirmblock[/b] is confusing the javascript and for some reason then ignoring the window.location request in the 2nd part of the OnClick eventAny ideas...Thanks Quote Link to comment Share on other sites More sharing options...
Telemachus Posted November 6, 2006 Share Posted November 6, 2006 This is what I tested and it worked:[code]<span onclick="var doYou = confirm('Do you really want to go?'); if (doYou) self.location.href = 'http://google.co.uk';">Test</span>[/code]I take it that's basically what you're trying to do. This is just a guess but it almost seems to me like where script is getting confused is in what to do with the true/false; return it as a variable, or return it on the event. Quote Link to comment Share on other sites More sharing options...
jaymc Posted November 6, 2006 Author Share Posted November 6, 2006 Worked greatThanks ! Quote Link to comment Share on other sites More sharing options...
fenway Posted November 6, 2006 Share Posted November 6, 2006 Basically, you were returning from the handler no matter what... you probably meant:[code]onclick="if( confirmblock() ) window.location='http://google.co.uk';"[/code] 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.