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

Categories

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

defect

Tracking

()

UNCONFIRMED

People

(Reporter: siccospam, Unassigned)

Details

Attachments

(1 file)

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

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.

<html>
<body>

<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;
    }
}
</script>

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

</body>
</html>
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,
mouse-click)

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
https://bugzilla.mozilla.org/show_bug.cgi?id=1472046

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.