473,385 Members | 1,370 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Why javascript strings not equal?

I have the following code:
---------------------------------------------
<html>
<head>
<script language="javascript">
function readHiddenField()
{
var string1 = 'hidden_field_l00';
var string2 = 'hidden_field_' + '100';

alert(string1 == string2);

var sampleRow = document.getElementById(string1);
alert(sampleRow.value);

var hiddenRow = document.getElementById(string2);
alert(hiddenRow.value);

}
</script>
</head>
<body>
<form>

<input type="hidden" id="hidden_field_l00" value="hello" />

<a href="#" onclick="readHiddenField();">Click 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. )

Mar 23 '06 #1
3 7007
On 23 mrt 2006, you wrote in comp.lang.javascript:
var string1 = 'hidden_field_l00';
var string2 = 'hidden_field_' + '100';


string1 contains the LOWERCASE LETTER L followed by 00

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Mar 23 '06 #2

se*********@gmail.com wrote:

<input type="hidden" id="hidden_field_l00" value="hello" />


There is a simple mistake. Your input id is "hidden_field_l00" not
"hidden_field_100" (in uppercase L instead of 1)

Mar 23 '06 #3
Thanks :-)

I now officially hate Courier New...

Just switched to Andale Mono font, where you can actually see the
difference between an l and a 1.

Mar 23 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.