admin管理员组文章数量:1302904
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>
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>
Share
Improve this question
asked Dec 14, 2011 at 16:18
KM.KM.
104k34 gold badges181 silver badges213 bronze badges
0
6 Answers
Reset to default 5problem 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>
Looks like an error in your HTML markup on these lines:
<input="hidden" id="1_a" value="AAA"/>
<input="hidden" id="1_b" value="BBB"/>
These need to be:
<input type="hidden" id="1_a" value="AAA"/>
<input type="hidden" id="1_b" value="BBB"/>
Notice the type
attributes.
Your element definition should be:
<input type="hidden" .../>
instead of
<input="hidden" .../>
Try starting your
id
with an alpha character (probably isn't the problem, but they should anyway).
First off, your inputs should be <input type="hidden" id="1_a" value="AAA"/>
<input type="hidden" id="1_b" value="BBB"/>
<input="hidden"
is wrong, you need:
<input type="hidden"
Working Demo
Because you have a wring markup. instead of
<input="hidden" id="1_a" value="AAA"/>
it should be
<input type="hidden" id="1_a" value="AAA"/>
本文标签: javascriptFirefox not getting value when using documentgetElementById()valueStack Overflow
版权声明:本文标题:javascript - Firefox not getting value when using: document.getElementById().value - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741693482a2392868.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论