SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Guru downtroden's Avatar
    Join Date
    Dec 2004
    Location
    illinois
    Posts
    971
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

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

    Code JavaScript:
    	$('#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.
    your brain reacts in the same way whether you are
    looking at something or thinking about it...

  2. #2
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,696
    Mentioned
    101 Post(s)
    Tagged
    4 Thread(s)
    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?
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  3. #3
    SitePoint Guru downtroden's Avatar
    Join Date
    Dec 2004
    Location
    illinois
    Posts
    971
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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
    Code JavaScript:
    if $(this).val() == '0') {

    to this?
    Code JavaScript:
    if ($(this).val() == '0') {

    I tried this and still receive broken output.
    your brain reacts in the same way whether you are
    looking at something or thinking about it...

  4. #4
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,696
    Mentioned
    101 Post(s)
    Tagged
    4 Thread(s)
    How would you suggest we go about duplicating the crash for ourselves?
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  5. #5
    SitePoint Guru downtroden's Avatar
    Join Date
    Dec 2004
    Location
    illinois
    Posts
    971
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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.

    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.
    your brain reacts in the same way whether you are
    looking at something or thinking about it...

  6. #6
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,696
    Mentioned
    101 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by downtroden View Post
    This may be reaching, but am I missing an opening parenthesis on the condition statements?
    Yes, that will definitely be a cause.

    Do you have a sample (broken) page online so that we may examine the cause of things?
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  7. #7
    SitePoint Guru downtroden's Avatar
    Join Date
    Dec 2004
    Location
    illinois
    Posts
    971
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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.
    your brain reacts in the same way whether you are
    looking at something or thinking about it...

  8. #8
    SitePoint Guru downtroden's Avatar
    Join Date
    Dec 2004
    Location
    illinois
    Posts
    971
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    HEY!

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

    Code JavaScript:
    	$(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();
    			}
    		});
    	});
    your brain reacts in the same way whether you are
    looking at something or thinking about it...


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •