views:

36

answers:

4

The alert is showing, but the value is not changing.... why?

<html>
    <head>
        <title>Test EuDock</title>
    </head>
    <body >
        <label id="labelID">test</label>
        <script type="text/javascript" >

            document.onkeyup = KeyCheck;

            function KeyCheck(e) {

                var KeyID = (window.event) ? event.keyCode : e.keyCode;

                switch(KeyID)
                {
                    case 39: // right arrow
                        document.getElementById('labelID').value="BLZ";
                        alert('ok');
                        break;
                }

            }
        </script>
    </body>
</html>
+4  A: 

Only input elements have the property value. You want innerHTML :

document.getElementById('labelID').innerHTML="BLZ";

innerHTML is the only attribute that is supported by all browsers.

innerText is not supported by Firefox and textContent is not supported by <= IE8.

Felix Kling
As my html says now: BLZ! ("Alright!", in portuguese) =)
Tom Brito
@Tom: Good that it works now :) Btw in German, BLZ is short for *Bankleitzahl* which means *bank identification number* :o)
Felix Kling
A: 

I don't think value is a property defined in the DOM for HTML elements. Try assigning to .innerHTML instead, and I think you'll get the result you want.

ngroot
A: 

Try this instead:

document.getElementById('labelID').innerText ="BLZ";
Steve Danner
A: 

The label element does not have a value property. use document.getElementById('labelID').innerHTML="BLZ"; instead.

Kangkan
it's what Felix says just 15 minutes before you.... ;)
Tom Brito
Ya, I realized as soon as I posted it. I was testing the same with Firebug at that time. :)
Kangkan