473,549 Members | 2,823 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Why javascript strings not equal?

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. )

Mar 23 '06 #1
3 7012
On 23 mrt 2006, you wrote in comp.lang.javas cript:
var string1 = 'hidden_field_l 00';
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*********@gma il.com wrote:

<input type="hidden" id="hidden_fiel d_l00" value="hello" />


There is a simple mistake. Your input id is "hidden_field_l 00" not
"hidden_field_1 00" (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

0
7751
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7992
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7511
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7840
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
3525
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3509
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1973
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1087
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
793
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.