I have found an odd anomaly with HTML text boxes and JavaScript that I have narrowed down to being a html/javascript peculiarity and I\'m hoping someone can educate me on.>
Your best bet is to put your code for handling the change in a function (say, handleTextChange
), and then call that function both from the change
event handler and when you make changes directly in your code.
HTML:
JavaScript:
function changeField(id, value) {
var field = document.getElementById(id);
if (field) {
field.value = value;
handleFieldChange(field);
}
}
Off-topic A couple of off-topic comments:
onchange
, not onChange
. In HTML, it doesn't matter; in XHTML, it matters, and the reflected property on the element is always all lower-case, so... And it's easier to type. :-)