Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Confirmed Submit does not take NO as an answer 2

Status
Not open for further replies.

cumap

IS-IT--Management
Jul 9, 2007
268
US
Hi all,

I'm having this cofirmed function, but it run as YES anyway no matter user clicked CANCEL or closed alert window.
Code:
function confirmSubmit()
	{
		if (confirm("This action can not be undone. Are you sure you want to continue?"));
		{
			document.form3.action="update.asp";
			document.form3.submit();
		}
	}

Thanks.
 
I think I understand the problem...

I'm not totally sure here but it seems to me that if I remove the ";" at the end of the IF statement, the function will work then. Would someone confirm this for me please.
 
it seems to me that if I remove the ";" at the end of the IF statement, the function will work then

That is correct. If statements do not require a semi-colon. If you write your javascript such that your opening bracket is on the same line as your if statement, then this will look and become less confusing to you. Here's a quick example to illustrate the point:
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "[URL unfurl="true"]http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">[/URL]
<html xmlns="[URL unfurl="true"]http://www.w3.org/1999/xhtml">[/URL]
<head>
<title>test</title>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<script type="text/javascript">

window.onload = function () {
   if (false) {
      alert("check1");
   }
   if (false); {
      alert("check2");
   }
};

</script>
<style type="text/css"></style>
</head>
<body>
</body>
</html>

-kaht

Lisa, if you don't like your job you don't strike. You just go in every day and do it really half-assed. That's the American way. - Homer Simpson
[small]<P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <.</B> bites again.[/small]
 
You are correct- the semi-colon at the end of the if statement serves as a line terminator. Therefore, regardless of the choice of the user, the script continues to execute the next statements underneath it, in this case, setting the action and submitting.

Greg
 
Thanks guys!!! so the semicolon is the line terminator that will terminate the if function. And I thought the semi-colon serves as "finish" on a line and start a new line. pitty me!!!

:)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top