Javascript else if not working

Can anyone tell me why this else if statement is not working? I have displayed both on the page to check their values after being processed, and they are indeed the same. However, it doesn’t work and I’m guessing it must be something with how I am comparing it. My code is below:

<script id="template-download" type="text/x-tmpl">
	function test(arg){
		output = arg;

		{% for (var i=0, file; file=o.files[i]; i++) { %}
			<tr class="template-download fade">
				{% if (file.error) { %}
					<td class="name"><span>{}</span></td>
					<td class="size"><span>{%=o.formatFileSize(file.size)%}</span></td>
					<td class="error" colspan="2"><span class="label label-important">{%=locale.fileupload.error%}</span> {%=locale.fileupload.errors[file.error] || file.error%}</td>

          // This is where I am having problems. I specify index zero and sooner or
         // later should match, but it never does and I'm not sure why??
        // So then I do else if ( "5.jpg" == ) and it does work....As you can
       // see that I test it in the line right below the else if, and displays the same as

				{% } else if ( output[0] == ) { %}
						<td class="name">{%=String(output[0])%}{%=String(}</td>
						<td class="preview">{% if (file.thumbnail_url) { %}
							<a href="{%=file.url%}" title="{}" rel="gallery" download="{}"><img src="{%=file.thumbnail_url%}"></a>
						{% } %}</td>
						<td class="name">
							<a href="{%=file.url%}" title="{}" rel="{%=file.thumbnail_url&&'gallery'%}" download="{}">{}</a>
						<td class="size"><span>{%=o.formatFileSize(file.size)%}</span></td>
						<td colspan="2"></td>
					{% } %}
						<td class="delete">
							<button class="btn btn-danger" data-type="{%=file.delete_type%}" data-url="{%=file.delete_url%}">
							<i class="icon-trash icon-white"></i>
							<input type="checkbox" name="delete" value="1">
		{% } %}

Any ideas? Thanks in advance!!!

Shouldn’t that be…

else if ( output[i] == )

Yeah I tried that first and it didn’t work…then I tested it out on the line below it…was thinking maybe that code would work, but I was wrong. For some odd reason

else if ( output[i] == )

will not work, but the following does…

else if ( "5.jpg" == )

5.jpg5.jpg ===> is the output I get from

<td class="name">{%=String(output[0])%}{%=String(}</td>

Try using


Ok, did that…now it runs but it displays all of them…even when I change output[i] to output[0] I should get only one that is true but I get all of them. Only one should match when I do it that way.

So you know…output_string was a JSON array

window.output = [];
test(output_string); // output_string is a JSON array that I send to a test function and then I assign a global variable 

function test(arg){
		output = arg;

Maybe that is what is messing it up…

I’ve tested and tested it…it is something to do with the JSON array…even though the value is the same it’s not returning true. If that makes any sense.

Here are the else if statements that works:

else if ( output[0].localeCompare( output[0] ) ) { %} // LOL of course ;)
else if ( "5.jpg" ) ) { %}

These doesn’t work

else if ( output[0].localeCompare( ) ) { %}
else if ( output[0].localeCompare( "5.jpg" ) ) { %}

Which doesn’t make any sense, because I have printed out output[0] and the value is 5.jpg.