Click to See Complete Forum and Search --> : onchange event not always triggered


lanikfs
05-16-2003, 02:14 PM
In IE 5.5, using a standard text-input field on a form, I've found that if you double-click on the field and select from the list of previous entries( and then of course click elsewhere ), the onchange event does not get triggered. Is there some way of handling this to make sure I catch the change to the field?

Jona
05-16-2003, 02:19 PM
Use onBlur in addition to onChange.

lanikfs
05-16-2003, 02:26 PM
Thanks for the reply Jona. So I guess you're saying have onblur call a JS function that checks the changed property of the field directly? I forget the code on how to do that.

Jona
05-16-2003, 02:27 PM
Post some code so I know what to work with. ;)

lanikfs
05-16-2003, 02:37 PM
Sure...thanks again.

<html>
<head>
<script language="JavaScript">
function chkChanged( field )
{
if( field.onchange ) // this is what I don't recall
return "yes";
else
return "no";
}
</script>
<body>
<form>
<input type="text" name="blah"
onblur="this.form.changed = chkChanged(this);">

<input type="hidden" name="changed">
</form>
</body>
</html>

Jona
05-16-2003, 02:45 PM
This code works (your code didn't). But what you might want to do is use onKeyDown and onKeyUp chkChanged(this).

<html>
<head>
<script language="JavaScript">
function chkChanged(field){
if(field.onchange) return "yes";
else return "no";
}
</script>
<body>
<form>
<input type="text" name="blah"
onblur="this.form.changed.value = chkChanged(this); alert(this.form.changed.value);">
<input type="hidden" name="changed">
</form>
</body>
</html>

Jona
05-16-2003, 02:59 PM
What I meant:

<html>
<head>
<script language="JavaScript">
function chkChanged(field){
if(field.onchange) return "yes";
else return "no";
}
</script>
<body>
<form>
<input type="text" name="blah"
onkeydown="this.form.changed.value = chkChanged(this); alert(this.form.changed.value);" onkeyup="this.form.changed.value = chkChange(this); alert(this.form.changed.value);">
<input type="hidden" name="changed">
</form>
</body>
</html>

lanikfs
05-16-2003, 03:14 PM
Hmm...I tried it and for some reason the field.onchange property is always false. Even when I type directly into the field and tab, it still indicates no change.

This code is actually in a jsp page. Could my compiler be doing something funny? I looked at the generated servlet code but don't see anything different. Just grasping at straws here.

Jona
05-16-2003, 03:21 PM
The server shouldn't indicate any errors.