I have a JavaScript function that I am trying to call when the confirm is true. I am using document.write because the source document is a .js file, not html.
Before the true condition is executing, I want a confirmation from the user that they are sure they want to reset the counter.
I have two attempts – the first of which is returning true of false, but not calling the resetCookie() function on the true condition.
The second attempt is, I think, syntactically incorrect, as it appears to do nothing.
First attempt:
document.write('<a href="" onclick="return alert(confirm(\'sure?\'));{resetCookie()}{};"><i>Reset counter</i></a>');
Second attempt:
document.write("<a href='javascript: if (confirm('Continue?')) { alert('You chose true') } else { alert('You chose false.') }; void('')'>Reset counter</a>");
Why don’t you just use the jscript confirm() function?
btw, your A tag is wrong (I’ll ignore for now that you can’t use document.write when already running):