I have the following code:
---------------------------------------------
<html>
<head>
<script language="javas cript">
function readHiddenField ()
{
var string1 = 'hidden_field_l 00';
var string2 = 'hidden_field_' + '100';
alert(string1 == string2);
var sampleRow = document.getEle mentById(string 1);
alert(sampleRow .value);
var hiddenRow = document.getEle mentById(string 2);
alert(hiddenRow .value);
}
</script>
</head>
<body>
<form>
<input type="hidden" id="hidden_fiel d_l00" value="hello" />
<a href="#" onclick="readHi ddenField();">C lick Me</a>
</form>
</body>
</html>
---------------------------------------------
To me, this should return three alert boxes that say "true", "hello",
and "hello". Instead, it returns "false", "hello", and then I get an
error for null reference because getElementById did not find the
element on the last call. What is it about the string concatenation
that makes it think these strings are not equivalent, and how can I
prevent this?
I know that if you replace '100' with 'X' in the field name and in the
script, then it works as expected, so this has to be somehow based on
number/string conversion, but there should not be any conversion going
on in the first place.
(Also, this is in IE 6, which is the only browser I need this to work
in, though I am curious if this is cross-browser behavior. )