Click to See Complete Forum and Search --> : Assigning values to text boxes in IE


nataliemac
04-18-2006, 12:21 PM
I have this code which works perfectly in FF, but not in IE. All I want is to fill in values in the second and third text boxes based on what the user enters in the first text box:

Javascript:
function updateFields() {
var room = document.getElementById('room');
var level = document.getElementById('level');
var area = document.getElementById('area');
if (room.value == '1001'||room.value == '1012' || room.value == '1151' || room.value == '1301' || room.value == '1504' || room.value == '1627') {
level.value = '1';
area.value = 'A';
}

HTML:
<label>Room Number: <input type='text' style='font-family:verdana;width:75px;font-size:12px' id='room' value='' onchange="updateFields();" /></label>
<label>Level: <input type='text' style='font-family:verdana;width:75px;font-size:12px' id='level' value='' /></label>
<label>Area: <input type='text' style='font-family:verdana;width:75px;font-size:12px' id='area' value='' /></label>

It seems so simple, I don't know why IE is being fussy.

Thanks.

TheBearMay
04-18-2006, 12:46 PM
This works fine in IE and FF:


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script type="text/javascript">
function updateFields() {
var room = document.getElementById('room');
var level = document.getElementById('level');
var area = document.getElementById('area');
if (room.value == '1001'||room.value == '1012' || room.value == '1151' || room.value == '1301' || room.value == '1504' || room.value == '1627') {
level.value = '1';
area.value = 'A';
}
}
</script>
</head>

<body>
<label>Room Number: <input type='text' style='font-family:verdana;width:75px;font-size:12px' id='room' value='' onchange="updateFields();" /></label>
<label>Level: <input type='text' style='font-family:verdana;width:75px;font-size:12px' id='level' value='' /></label>
<label>Area: <input type='text' style='font-family:verdana;width:75px;font-size:12px' id='area' value='' /></label>
</body>
</html>Only thing I did was add an extra } to close the function...

nataliemac
04-18-2006, 01:27 PM
Doh. I checked my actual page code and I do have the extra }. I must have missed it when I copied/pasted.

Interesting, though. Why does it work for you?

nataliemac
04-18-2006, 01:33 PM
Oh, I found a fix. IE seems to prefer onblur to onchange.

I hate that stupid browser.