473,545 Members | 2,788 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Noobie onclick, confirm, return false ??

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

<input type="submit" onclick="if(!co nfirm('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 11647
GiJeet wrote:
Hello, I'm trying to figure this code out.

<input type="submit" onclick="if(!co nfirm('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.c omwrote:
Hello, I'm trying to figure this code out.

<input type="submit" onclick="if(!co nfirm('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="retur n 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 bugRiddenCrashP ronePieceOfJunk = (
navigator.userA gent.indexOf('M SIE 5') != -1
&& navigator.userA gent.indexOf('M ac') != -1
) // Plone, register_functi on.js:16
Jun 27 '08 #5
Lee
VK said:
>
On May 19, 11:06 pm, GiJeet <gij...@yahoo.c omwrote:
>Hello, I'm trying to figure this code out.

<input type="submit" onclick="if(!co nfirm('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="retur n 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
6159
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 me</A> or <A HREF="http://SomeWebSite" OnClick="return confirm('Are you
4
2835
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 then submit the form... Could someone correct this lump of code for us pleaseeeeeeee ;o) <input name="Submit" type="button"...
2
1647
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 browser not complain about illegal use?
13
38534
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. However, this is not the case with the IE7 I am using. What has changed?
4
13445
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 'onClientClick()' event of the button. I have a required field validator for the text boxes in the grid view also. The dropdown list box contains 2 values 'Open'...
8
4352
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 submitted, if Cancel - nothing should happen. The ASP.NET code looks like this: btnSubmit.Attributes.Add("onClick", "if (!(" &...
5
8668
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
1985
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 page.Otherwise,returns false. Now,After validation , the tab which is actually activated willl be as it is after returning false. This is working fine in...
0
7432
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7689
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7943
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7786
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6022
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5359
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3490
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
1919
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
743
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.