473,382 Members | 1,480 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Noobie onclick, confirm, return false ??

Hello, I'm trying to figure this code out.

<input type="submit" onclick="if(!confirm('Are you sure?') return
false; "... />

I know that if you return false in an event like this onclick it
prevents the default behavior of the event. So, in the onclick of a
button the default behavior is to submit the form.

Confirm returns the value 1 if the user clicks OK and the value 0 if
the user clicks Cancel and 1 is treated as true and 0 is treated as
false right?

so, if the user click OK, a 1 is returned but the ! turns it to false
and the form should not submit even thou the user click OK, and then
there's a return false right after the confirm function. so what's
happening here? do we even need the return false statement here?

TIA
g
Jun 27 '08 #1
5 11623
GiJeet wrote:
Hello, I'm trying to figure this code out.

<input type="submit" onclick="if(!confirm('Are you sure?') return
false; "... />

I know that if you return false in an event like this onclick it
prevents the default behavior of the event. So, in the onclick of a
button the default behavior is to submit the form.
No, the default behavior is to activate the element.
Confirm returns the value 1 if the user clicks OK and the value 0 if
the user clicks Cancel
No, it returns `true' or `false'. Boolean is a type of its own in
ECMAScript implementations.
and 1 is treated as true and 0 is treated as false right?
If you mean "evaluated in boolean expressions" by "treated", then you are
correct.
so, if the user click OK, a 1 is returned
`true' is returned.
but the ! turns it to false
Correct.
and the form should not submit even thou the user click OK,
Non sequitur. The default action of the `click' event is to activate the
element, not to submit the form. That is the default action of the form's
submit event, and so must be handled in the `onsubmit' event handler attribute.
and then there's a return false right after the confirm function.
Doesn't matter.
so what's happening here? do we even need the return false statement here?
The entire code is bogus. However, return window.confirm(...) accomplishes
the same: nothing of consequence here, preventing form submission if the
dialog is canceled within the `onsubmit' attribute value.
PointedEars
--
Anyone who slaps a 'this page is best viewed with Browser X' label on
a Web page appears to be yearning for the bad old days, before the Web,
when you had very little chance of reading a document written on another
computer, another word processor, or another network. -- Tim Berners-Lee
Jun 27 '08 #2
>The default action of the `click' event is to activate the
>element, not to submit the form. That is the default action of the form's
submit event, and so must be handled in the `onsubmit' event handler attribute.
so why does the form get submitted when you click OK?
Jun 27 '08 #3
VK
On May 19, 11:06 pm, GiJeet <gij...@yahoo.comwrote:
Hello, I'm trying to figure this code out.

<input type="submit" onclick="if(!confirm('Are you sure?') return
false; "... />
<input type="submit" onclick="return confirm('Are you sure?');">

should work. Yet there is a long standing tradition to form submit and
not button submit.

<form onsubmit="return confirm('Are you sure?');">

I remember they were some serious reasons for this choice but I don't
remember them now nor I know if they are still actual.
Jun 27 '08 #4
GiJeet wrote:
>The default action of the `click' event is to activate the
element, not to submit the form. That is the default action of the form's
submit event, and so must be handled in the `onsubmit' event handler attribute.

so why does the form get submitted when you click OK?
I have already explained that in the very paragraph you quoted.

Please leave the attribution line in.
PointedEars
--
var bugRiddenCrashPronePieceOfJunk = (
navigator.userAgent.indexOf('MSIE 5') != -1
&& navigator.userAgent.indexOf('Mac') != -1
) // Plone, register_function.js:16
Jun 27 '08 #5
Lee
VK said:
>
On May 19, 11:06 pm, GiJeet <gij...@yahoo.comwrote:
>Hello, I'm trying to figure this code out.

<input type="submit" onclick="if(!confirm('Are you sure?') return
false; "... />

<input type="submit" onclick="return confirm('Are you sure?');">

should work. Yet there is a long standing tradition to form submit and
not button submit.

<form onsubmit="return confirm('Are you sure?');">

I remember they were some serious reasons for this choice but I don't
remember them now nor I know if they are still actual.
Early browsers didn't all support an onclick handler for the submit button.
--

Jun 27 '08 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Alan | last post by:
I post this message here because I have post in js.group before, but onone answer, thus i guess this is ASP issue. <A HREF="http://SomeWebSite" OnClick="return confirm('Are you sure?')">Click...
4
by: @sh | last post by:
Can anyone help out here please, we have a button that when pressed will alert the user, should they cancel no action is taken, however should they confirm, the script will disable the button and...
2
by: s_m_b | last post by:
Do you have to use the onClick attrib to have return false work? i.e. is it possible to do <a href="javascript:somefunct();return false;"> and have the page not reload with 'false' or the...
13
by: alvin.yk | last post by:
Hi, Normally, a piece of code such as <a href="http://www.yahoo.com" onclick="alert('hello');return false;">link</a> will stop the browser from actually going to href's destination....
4
by: =?Utf-8?B?c3Jpbml2YXM=?= | last post by:
Hi, I'm having an ASP.net page with a dropdown list box named ddlStatus, a button and editable gridview. I wrote a small javascript function "OnSave()" and called it on the event...
8
by: Peter Afonin | last post by:
Hello, I'm using Javascript in ASP.NET application to check whether at least one checkbox in datagrid has been checked. If validation fails, the user gets a warning. If he clicks OK, the form is...
5
by: dangt85 | last post by:
Hello, I have the following page: ... <style type="text/css"> body { font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; }
2
Soniad
by: Soniad | last post by:
Hi, I have ASP page where there are three tabs,each showing different content. Each tab have cancel button and save button. If validation is proper; then, Save button submits the...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.