Jquery change function if statement woes…

Is this not formatted correctly? I’m using jquery tools for tabs and this little addition on my part is causing a ‘crash’.


	$('#work_count').change(function(){
		if $(this).val() == '0') {
			$("#next_1").hide();
		} else if $(this).val() == '1') {
			$("#next_2").hide();
		} else if $(this).val() == '2') {
			$("#next_3").hide();
		}
	});

Thanks for any help.

As it’s more than troublesome for us to attempt to duplicate your environment without more information, let’s work out what’s causing the crash.

Does it still crash when only the hide statements are commented out?

interesting, didn’t think to do just those, but alas…*commented those and still bombs.

Basically it’s not hiding the ‘page’ divs for the tab content, if the ‘if’ statement is present.

okay, just got firebug to tell me ‘syntax error, missing before condition’

This may be reaching, but am I missing an opening parenthesis on the condition statements?

Current


if $(this).val() == '0') {

to this?


if ($(this).val() == '0') {

I tried this and still receive broken output. :frowning:

How would you suggest we go about duplicating the crash for ourselves?

Good question. I have no idea how you can repeat this, because I don’t know what’s going wrong. Noob js person, trying to do something that seems simple, but apparently app server logic is easier than javascript. :frowning:

Also, just tried the JSLint link in your sig, i WAS missing an open parenthesis, but now it’s saying “Implied global: $ 1,2,4,5,6,7,8,9, document 1”

What’s that mean? Not the best error explanation.

Yes, that will definitely be a cause.

Do you have a sample (broken) page online so that we may examine the cause of things?

unfortunately no, i don’t. And there’s too much application logic built into the page that I can’t strip out in a timely fashion for the page to work.

Thanks for the help though. I’ll just keep trying.

HEY!

got it working the way I was expecting. For anyone else…*here’s the final product.


	$(document).ready(function() {
		$('#work_count').change(function(){
			//alert($(this).val());
			if ($(this).val() <= "1") {
				$("#next_1").hide();
			} else if ($(this).val() == "2") {
				$("#next_1").show();
				$("#next_2").hide();
			} else if ($(this).val() == "3") {
				$("#next_1").show();
				$("#next_2").show();
			}
		});
	});