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) ...
Status: RESOLVED INVALID
:
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)
:
Mentors:
Depends on:
Blocks:
  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:
(edit)
QA Whiteboard:
Iteration: ---
Points: ---
Has Regression Range: ---
Has STR: ---


Attachments

Description 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))
		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.
Comment 1 Tuukka Tolvanen (sp3000) 2004-11-24 06:04:50 PST
please attach a testcase
Comment 2 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) {
		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 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 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.