Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firefox not getting value when using: document.getElementById().value

When I click on the Click Here!!! I get the two alert() messages but instead of the values BBB and ZZZ that I expect, I get undefined and undefined.

Any ideas what I'm doing wrong? I'm running Firefox 8.0, works in IE 8

<HTML>
<HEAD>
</HEAD>

<BODY>

<div id="1_0">
    <div id='1_1'  style="background-color: yellow;">
        <input="hidden" id="1_a" value="AAA"/>
        <input="hidden" id="1_b" value="BBB"/>
        some text, and some more
        <div>
            <div style="background-color: silver;" onclick="alert(document.getElementById('1_b').value);alert(document.getElementById('1_z').value);">
                Click Here!!!
            </div>
        </div>
    </div>
</div>


<input="hidden" id="1_z" value="ZZZ"/>

</BODY>
</HTML>
like image 565
KM. Avatar asked Jun 30 '26 03:06

KM.


1 Answers

problem is with the input=hidden. It should be <input type="hidden">

<HTML>
<HEAD>
</HEAD>

<BODY>

<div id="1_0">
    <div id='1_1'  style="background-color: yellow;">
        <input type="hidden" id="1_a" value="AAA"/>
        <input type="hidden" id="1_b" value="BBB"/>
        some text, and some more
        <div>
            <div style="background-color: silver;" onclick="alert(document.getElementById('1_b').value);alert(document.getElementById('1_z').value);">
                Click Here!!!
            </div>
        </div>
    </div>
</div>


<input type="hidden" id="1_z" value="ZZZ"/>

</BODY>
</HTML>
like image 119
paulslater19 Avatar answered Jul 01 '26 16:07

paulslater19



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!