The default bug view has changed. See this FAQ.

JavaScript: set on 'onClick' event of a button a function using Confirm(msg) and event.returnValue, behavior not the one expected

RESOLVED INVALID

Status

()

Core
DOM: Core & HTML
--
major
RESOLVED INVALID
13 years ago
13 years ago

People

(Reporter: C H, Unassigned)

Tracking

1.7 Branch
x86
Windows 2000
Points:
---

Firefox Tracking Flags

(Not tracked)

Details

(Reporter)

Description

13 years ago
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))
		event.returnValue=true;
	else
		event.returnValue=false;
}

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:
1.
2.
3.
(Reporter)

Updated

13 years ago
Summary: JavaScript: set on 'onClick' event of a button a function using Confirm(msg) and event.returnValue, behavior not the on expected → JavaScript: set on 'onClick' event of a button a function using Confirm(msg) and event.returnValue, behavior not the one expected
please attach a testcase

Updated

13 years ago
Assignee: bryner → firefox
Component: Build Config → General
QA Contact: asa → firefox.general

Comment 2

13 years ago
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) {
		window.document.getElementById("action").value="edit";
		window.document.getElementById("client_indiv_id").value=user_id;
		window.document.getElementById("list_form").submit();
	}

	function add(user_id) {
		if (confirm("Are you sure you want to add this person to your contact list?")) {
		
window.location.href="edit_local_to_client.php?action=insert&client_indiv_id="+user_id
		}
	}
</script>

<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">
		<tr>
			<th bgcolor="#cccccc">Edit or Add to Your Watch List</th>
			<th>Name</th>
			<th>Office</th>
			<th>Phone</th>
			<th>Mobile</th>
			<th>Email</th>
		</tr>
		<tr>
			<td bgcolor="#CCCCCC"><button onClick="edit(5)">Edit</button> <button
onClick="add(5)">Add</button></td>
			<td>John Doe</td>
			<td>FMSM&nbsp;</td>
			<td>&nbsp;</td>
			<td>&nbsp;</td>
			<td><a href="mailto:"></a>&nbsp;</td>
		</tr>
		<tr>
			<td bgcolor="#CCCCCC"><button onClick="edit(6)">Edit</button> <button
onClick="add(6)">Add</button></td>
			<td>Jane Doe</td>
			<td>FMSM&nbsp;</td>
			<td>&nbsp;</td>
			<td>&nbsp;</td>
			<td><a href="mailto:"></a>&nbsp;</td>
		</tr>
	</table>
</form>

Comment 3

13 years ago
Decreasing Severity form critcal to major (dose not cause crash or loss of data)
Moving to "Core" - "Dom" 
Assignee: firefox → general
Severity: critical → major
Component: General → DOM
Product: Firefox → Core
QA Contact: firefox.general → ian
Version: unspecified → 1.0 Branch

Updated

13 years ago
Component: DOM → DOM: Level 0
Hardware: Other → PC
Version: 1.0 Branch → 1.7 Branch
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.
Status: UNCONFIRMED → RESOLVED
Last Resolved: 13 years ago
Resolution: --- → INVALID
You need to log in before you can comment on or make changes to this bug.