[SOLVED] confirm box

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
User avatar
Think Pink
Forum Contributor
Posts: 106
Joined: Mon Aug 02, 2004 3:29 pm

confirm box

Post by Think Pink »

hello. pl help with the follwing;

I want to make a confirm box. If someone clicks OK, the form is submitted, if clickes Cancel nothing happends.

This is what I have so far:

Code: Select all

<script language="JavaScript">
<!--
function confirm_entry()
&#123;
var agree=confirm("OK to Continue \r Cancel to stop the execution");
if (agree)

&#123; 
// when ok is pressed the form is submitted
&#125;

else
&#123;
// when cancel is pressed nothing happends
&#125;
&#125;
-->
</script>

<form name="" action="test.php" method="post" onSubmit="confirm_entry();">
<input type="submit">
</form>
in this situation, if I click ok, the form is submitted, but the same thing is happening if i click cancel
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

try

Code: Select all

function confirm_entry()
&#123;
  return confirm('OK to Continue\nCancel to stop the execution');
&#125;
User avatar
Think Pink
Forum Contributor
Posts: 106
Joined: Mon Aug 02, 2004 3:29 pm

confirm box

Post by Think Pink »

not working
User avatar
voltrader
Forum Contributor
Posts: 223
Joined: Wed Jul 07, 2004 12:44 pm
Location: SF Bay Area

Post by voltrader »

This works:


Code: Select all

<script language="JavaScript">
<!--
function confirm_entry()
&#123;
var agree=confirm("OK to Continue \r Cancel to stop the execution");
if (agree)

&#123;
// when ok is pressed the form is submitted
&#125;

else
&#123;
// when cancel is pressed nothing happends
return false;
&#125;
&#125;
-->
</script>

<form name="" action="test.php" method="post" onSubmit="return confirm_entry();">
<input type="submit">
</form>
User avatar
Think Pink
Forum Contributor
Posts: 106
Joined: Mon Aug 02, 2004 3:29 pm

confirm box

Post by Think Pink »

thx. works great
User avatar
Pyrite
Forum Regular
Posts: 769
Joined: Tue Sep 23, 2003 11:07 pm
Location: The Republic of Texas
Contact:

Post by Pyrite »

Cool.
Post Reply