/    Sign up×
Community /Pin to ProfileBookmark

Assigning values to text boxes in IE

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:

[CODE]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’;
}[/CODE]

HTML:

[CODE] <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>[/CODE]

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

Thanks.

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@TheBearMayApr 18.2006 — This works fine in IE and FF:

<i>
</i>&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"&gt;
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;&lt;/title&gt;
&lt;meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"&gt;
&lt;script type="text/javascript"&gt;
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';
}
}
&lt;/script&gt;
&lt;/head&gt;

&lt;body&gt;
&lt;label&gt;Room Number: &lt;input type='text' style='font-family:verdana;width:75px;font-size:12px' id='room' value='' onchange="updateFields();" /&gt;&lt;/label&gt;
&lt;label&gt;Level: &lt;input type='text' style='font-family:verdana;width:75px;font-size:12px' id='level' value='' /&gt;&lt;/label&gt;
&lt;label&gt;Area: &lt;input type='text' style='font-family:verdana;width:75px;font-size:12px' id='area' value='' /&gt;&lt;/label&gt;
&lt;/body&gt;
&lt;/html&gt;
Only thing I did was add an extra } to close the function...
Copy linkTweet thisAlerts:
@nataliemacauthorApr 18.2006 — 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?
Copy linkTweet thisAlerts:
@nataliemacauthorApr 18.2006 — Oh, I found a fix. IE seems to prefer onblur to onchange.

I hate that stupid browser.
×

Success!

Help @nataliemac spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.14,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...