Jump to content

Javascript Problem


Guest yunkhun

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>

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...