Javascript/Jquery cannot use 0 or 1 as the value of the variable?

I have a form with a radio select box. There are 6 options. The values of these options are 0 through 5. I'm using Jquery to retrieve the value of the checked radio button upon submission of the form.

var nextStatus;
nextStatus = $j('input[name="Status"]:radio:checked').val();

This works fine when the status is 2 or above, however, when the status is 0 or 1, it does not set the variable at all. I cannot figure out why it would matter that the value of the radio select button being 0 or 1 would cause jquery/javascript to not set this variable.

<label><input type='radio' name='Status' value='0' id='0' />Status0</label><br />
<label><input type='radio' name='Status' value='1' id='1' />Status1</label><br />
<label><input type='radio' name='Status' value='2' id='2' />Status2</label><br />
<label><input type='radio' name='Status' value='3' id='3' />Status3</label><br />
<label><input type='radio' name='Status' value='4' id='4' />Status4</label><br />
<label><input type='radio' name='Status' value='5' id='5' />Status5</label><br />

When I use parseInt() on this variable, any status 2 or above comes back fine, but if its the 0 or 1, it returns NaN. When I use typeof() on the var, it returns "string" (after removing parseInt()). I'm totally stumped on this. I SHOULD be able to use a 0 or a 1 as a variable value, should I not?

If I change the values of the radio button to 2 through 7 instead 0 through 5, using firebug, it works fine. I'd rather not do that as this radio select is programatically generated from a database using foreign keys, and it would be difficult to modify all of that for an issue that to my knowledge shouldn't even be happening.

If anyone has run into this, please help!!!


It's perhaps worth pointing out that, under HTML 4, your input elements' id s are invalid: they shouldn't start with a numeric character. – David Thomas 14 mins ago

I appened a string to the beginning of the IDs, and this fixed the issue!

Works for me:

Please create a working pared-down test case showing your problem (preferably at JSFiddle).

Need Your Help

Quick Probability Concept: N-bit strings

computer-science probability probability-theory

Suppose you generate an N-bit string (composed of only 1's and 0's).

How to determine when PNG24 converted to PNG8 is lossless?

optimization image-processing png

Hey, i'm using a program called pngquant to convert 24 bit PNGs to 8-bit PNGs. Everything seems to work fine, and I don't notice any loss of quality for icons and other images that don't contain to...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.