Jump to content
Sign in to follow this  
Guest yunkhun

Javascript Problem

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>

Share this post


Link to post
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

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...