Open Bug 339573 Opened 15 years ago Updated 3 years ago

TAB key focuses the next field in HTML form onChange event even if return value for the event was false


(Core :: DOM: Events, defect, P5)






(Reporter: siccospam, Unassigned)



(1 file)

User-Agent:       Mozilla/5.0 (Windows; U; Windows NT 5.0; nl; rv: Gecko/20060426 Firefox/
Build Identifier: Mozilla/5.0 (Windows; U; Windows NT 5.0; nl; rv: Gecko/20060426 Firefox/

When you TAB from one textfield to the next in a HTML form and use the onChange event of the first field to check the value, the focus will go to the next field, even if the return value in the onChange event was false. If you want to check for a value, the onChange event is the right place/time to do so, but if a typed textfield value was incorrect, you don't want to loose the focus on that field.

Reproducible: Always

Steps to Reproduce:
Use the HTML and javascript below to see what happens and compare with the way Internet Explorer handles it.


<script type="text/javascript">
function fieldIsValid(field){
    if (field.value != "HellO WorlD"){
        alert("Value is not ok.");
        field.value = "";
        return false;
    } else{
        alert("Value is ok.");
        return true;

<input type="text" onChange="return fieldIsValid(this)">
<input type="text" >

Assignee: nobody → events
Component: Form Manager → DOM: Events
OS: Windows 2000 → All
Product: Firefox → Core
QA Contact: form.manager → ian
Hardware: PC → All
Version: unspecified → Trunk
Related to or equal to Bug 267675
> Related to or equal to bug 267675

Don't think so. Ref my comment on bug 267675

This bug describes the fact that ff dos'nt respect the return
value from onchange-handler and always selects next/previous/any control
according to the action which triggered the onchange-event (tab, shift/tab,

The problem may be handled by:

function myOnChange(field)
	if (field.value!='Ok value')
		window.selectedField = field;
		if (!/^Mozilla/.test(navigator.userAgent)) 	{  field.focus();  }
		else                                        {  setTimeout('window.selectedField.focus()', 1); }  // Workaround for mozilla 'bug'

		return false;  // Respected by IE only
	return true;

.. but it would have been nice if it could be fixed to work as in IE
Assignee: events → nobody
QA Contact: ian → events

Move all DOM bugs that haven’t been updated in more than 3 years and has no one currently assigned to P5.

If you have questions, please contact :mdaly.
Priority: -- → P5
You need to log in before you can comment on or make changes to this bug.