Last Comment Bug 271528 - JavaScript: set on 'onClick' event of a button a function using Confirm(msg) and event.returnValue, behavior not the one expected
: JavaScript: set on 'onClick' event of a button a function using Confirm(msg) ...
Product: Core
Classification: Components
Component: DOM: Core & HTML (show other bugs)
: 1.7 Branch
: x86 Windows 2000
-- major (vote)
: ---
Assigned To: general
: Hixie (not reading bugmail)
: Andrew Overholt [:overholt]
Depends on:
  Show dependency treegraph
Reported: 2004-11-24 04:59 PST by C H
Modified: 2004-12-05 20:08 PST (History)
4 users (show)
See Also:
Crash Signature:
QA Whiteboard:
Iteration: ---
Points: ---
Has Regression Range: ---
Has STR: ---


Description User image C H 2004-11-24 04:59:36 PST
User-Agent:       Mozilla/5.0 (Windows; U; Windows NT 5.0; rv:1.7.3) Gecko/20041001 Firefox/0.10.1
Build Identifier: Mozilla/5.0 (Windows; U; Windows NT 5.0; rv:1.7.3) Gecko/20041001 Firefox/0.10.1

On the 'onClick' event of a button, I have a javascript function as follow:
function myFunction(msg)
	if (confirm(msg))

This function is there to allow the user to confirm or not the action attached
to the button such as 'You are about to delete this item. Are you sure?'
OK - do the action;
CANCEL - cancel the action.

On firefox, regadless of the confirmation button chosen (OK or CANCEL), it
behaves as if the OK button was used.

Reproducible: Always
Steps to Reproduce:
Comment 1 User image Tuukka Tolvanen (sp3000) 2004-11-24 06:04:50 PST
please attach a testcase
Comment 2 User image Chris Howard 2004-11-24 12:25:52 PST
Not sure if this person is describing the same problem I am having but it is
close enough..  

I have a form and in the form is several <button>s that have an onClick event. 
Some of the functions that the onClick events call simply contain
window.location.href="url here".  However, instead of just the function
processing and the user being forwarded to the next page, the next page gets
processed and the user is forwarded to the action of the form containing the
<button> as if it was an <input type=submit>.  I've had this happen with
functions containing an "if confirm(msg)" and without.

<script language="JavaScript">
	function edit(user_id) {

	function add(user_id) {
		if (confirm("Are you sure you want to add this person to your contact list?")) {

<a href="edit_client.php?action=new">Create New</a>
<form action="edit_client.php" method="post" name="list_form" id="list_form">
	<input type="hidden" name="action" id="action" value="edit">
	<input type="hidden" name="client_indiv_id" id="client_indiv_id" value="">
	<table border="1" cellspacing="1" cellpadding="3">
			<th bgcolor="#cccccc">Edit or Add to Your Watch List</th>
			<td bgcolor="#CCCCCC"><button onClick="edit(5)">Edit</button> <button
			<td>John Doe</td>
			<td><a href="mailto:"></a>&nbsp;</td>
			<td bgcolor="#CCCCCC"><button onClick="edit(6)">Edit</button> <button
			<td>Jane Doe</td>
			<td><a href="mailto:"></a>&nbsp;</td>
Comment 3 User image Gary van der Merwe 2004-11-24 13:52:13 PST
Decreasing Severity form critcal to major (dose not cause crash or loss of data)
Moving to "Core" - "Dom" 
Comment 4 User image Boris Zbarsky [:bz] (still a bit busy) 2004-12-05 20:08:25 PST
Chris, the default type of <button>, if no type is explicitly specified is
"submit".  IE gets this wrong.

Reporter, event.returnValue is an IE-ism that's not part of the DOM Events
standard.  It makes no sense outside IE's event processing model, where events
don't have return values at all (and instead can be prevented from propagating
by calling stopPropagation() or preventDefault() on them, depending on what the
goal is).

Marking invalid.

Note You need to log in before you can comment on or make changes to this bug.