Forum Moderators: open

Message Too Old, No Replies

I can't get a Javascript to work > < on inner html

inner html, case, element by id don't play well together

         

Baruch Menachem

4:11 am on Dec 21, 2008 (gmt 0)

10+ Year Member



I am working my way through a textbook. I have firebug, but the message I am getting (lack of a '{') seems to be wrong

What obvious thing am I missing?
the javascript


function changeText()
{
var error = document.getElementById('goofee').value;


switch (error)
{
case 3: gufee="refer to maker"; break;
case 24: gufee="account closed"; break;
case 26: gufee="account is NSF"; break;
case 27: gufee="customer paid direct"; break;
case 30: gufee="claimant received benefit"; break;
case 68: gufee="paying bank will not pay item on collection"; break;

}

document.getElementById('boldStuff2').innerHTML = gufee;

}

and the HTML part


<input type="text" name="code" size="2" id="goofee" onblur ="changeText()" />
reason : <em id="boldStuff2">__</em>

lavazza

4:38 am on Dec 21, 2008 (gmt 0)

10+ Year Member



How about...

instead of
onblur ="changeText()"
which is declaring a function and should be followed by a {

try
onblur ="changeText();"
which - with a semi-colon(;) - calls a function

Baruch Menachem

8:14 pm on Dec 21, 2008 (gmt 0)

10+ Year Member



I did something that would cause howls of derision from folks who know what they are doing, but it works. The problem I was having was that I was trying to compare a string input with an integer case statement. My fix was to multiply error by 1. It turned the number into an integer rather than a string, and it worked!

lavazza

8:33 pm on Dec 21, 2008 (gmt 0)

10+ Year Member



That's actually the way it does (or, rather, can) work in javascript, which is a loosely-typed (aka dynamic) language

Baruch Menachem

9:01 pm on Dec 21, 2008 (gmt 0)

10+ Year Member



I first learned computer on apple II basic and Pascal. In basic you had to keep strings and integers distinct, and those old enough to remember Pascal remember how ferociously typed that was. I just made the mistake of assuming that if I was inputting a number, the input would be an integer. The computer had other plans.