Jump to content

Javascript Problem


Guest yunkhun
 Share

Recommended Posts

Guest yunkhun

do you know why this doesn't work in chrome and safari? thanks...<html><head><script type="text/javascript">function show_confirm(){var r=confirm("Press a button");if (r==true) { document.write("You pressed OK!"); }else { document.write("You pressed Cancel!"); }}</script></head><body><input type="button" onclick="show_confirm()" value="Show a confirm box" /></body></html>

Link to comment
Share on other sites

not the best of examples, as it seems to go through a loop trying to open a new page.try this:<html><head><script type="text/javascript">function show_confirm(){var r=confirm("Press a button");var x=document.getElementById("swap");if (r==true) { //document.write("You pressed OK!"); x.innerHTML="You pressed OK!"; }else { //document.write("You pressed Cancel!"); x.innerHTML="You pressed Cancel!"; } }</script></head><body><div id="swap"><input type="button" onclick="show_confirm();" value="Show a confirm box" /></div></body></html>

Edited by dsonesuk
Link to comment
Share on other sites

do you know why this doesn't work in chrome and safari? thanks...<html><head><script type="text/javascript">function show_confirm(){var r=confirm("Press a button");if (r==true) { document.write("You pressed OK!"); }else { document.write("You pressed Cancel!"); }}</script></head><body><input type="button" onclick="show_confirm()" value="Show a confirm box" /></body></html>
this is the example, w3school gavehttp://w3schools.com/js/tryit.asp?filename=tryjs_confirm
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...