Results 1 to 7 of 7

Thread: Passing value error

  1. #1
    Join Date
    Mar 2010
    Location
    Florida
    Posts
    512
    Thanks
    9
    Thanked 61 Times in 59 Posts

    Default Passing value error

    I do not know why the value is always passing zero but I think it has something to do with the ready function that I'm using in Jquery.
    Code:
    $(function(){
    change(0);
    });
    
    $(document).on('click','#nav>li',function(){
    change(1);
    });
    
    function change(value){
    $('#nav>li').removeClass('selected').addClass('not');
    $('#nav>li:eq('+value+')').removeClass('not').addClass('selected');
    }
    That's fails to change the class. It does switch it the first time the page loads. After that it fails to do that.
    Last edited by Deadweight; 12-26-2013 at 10:41 PM. Reason: Resolved
    -DW [Deadweight]
    Resolving your thread: First Post: => EDIT => Lower right: => GO ADVANCED => Top Advance Editor drop down: => PREFIX:Resolved

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    There could also be other problems. But the code is missing closing ' marks (added in red below - two places):

    Code:
    function change(value){
    $('#nav>li').removeClass('selected').addClass('not');
    $('#nav>li:eq('+value+')').removeClass('not').addClass('selected');
    }
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. #3
    Join Date
    Mar 2010
    Location
    Florida
    Posts
    512
    Thanks
    9
    Thanked 61 Times in 59 Posts

    Default

    Oh sorry, that's not the error. I was typing it from my phone and just forgot to place them on the retype. they actually have the " ' ". Thanks tho
    -DW [Deadweight]
    Resolving your thread: First Post: => EDIT => Lower right: => GO ADVANCED => Top Advance Editor drop down: => PREFIX:Resolved

  4. #4
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Works fine here in Chrome:

    Code:
    <!DOCTYPE html>
    <html>
    <head>
    <title></title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <style type="text/css">
    .selected {
    	color: red;
    }
    </style>
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8/jquery.min.js"></script>
    <script type="text/javascript">
    $(function(){
    change(0);
    });
    
    $(document).on('click','#nav>li',function(){
    change(1);
    });
    
    function change(value){
    $('#nav>li').removeClass('selected').addClass('not');
    $('#nav>li:eq('+value+')').removeClass('not').addClass('selected');
    }
    </script>
    </head>
    <body>
    <ul id="nav">
    <li>1</li>
    <li>2</li>
    <li>3</li>
    </ul>
    </body>
    </html>
    What browser are you using?
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  5. #5
    Join Date
    Mar 2010
    Location
    Florida
    Posts
    512
    Thanks
    9
    Thanked 61 Times in 59 Posts

    Default

    I'm using Chrome and here is a live example:
    http://thebcelements.com/dhtml_test/kennel/
    -DW [Deadweight]
    Resolving your thread: First Post: => EDIT => Lower right: => GO ADVANCED => Top Advance Editor drop down: => PREFIX:Resolved

  6. #6
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Change bce.js to:

    Code:
    $(function() {
    	selection = 0;
    	setInterval(get_width,100);
    	changeit(0);
    });
    
    $(document).on('click','#nav>li',function (){
    	//selection = $(this).index();
    	//$('.selected').switchClass('selected','not',100);	
    	//$(this).switchClass('not','selected',100);
    	changeit(1);
    });
    
    function get_width(){
    	var change = $('body').width()-$('#nav').outerWidth(true)-10;
    	$('#outline>li:eq(1)').width(change);
    };
    
    function changeit(value){
    	$('#nav>li').removeClass('selected').addClass('not');
    	$('#nav>li:eq('+value+')').removeClass('not').addClass('selected');
    	$('#developer').text(value);
    };
    In get_width() there was an undeclared global var change which was overwriting the function change after it was used the first time (100ms after document ready). By declaring the change var formally in the function and changing the function change()'s name to changeit, the conflict is avoided. Either of these actions alone should suffice to fix the problem. But I did both, just to be on the safe side.

    Further, the change (now changeit) function had an error - the_value - was undefined. I changed that to value to avoid that error.
    Last edited by jscheuer1; 12-26-2013 at 07:07 PM. Reason: add explanation
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  7. The Following User Says Thank You to jscheuer1 For This Useful Post:

    Anne Arbor (01-23-2014)

  8. #7
    Join Date
    Mar 2010
    Location
    Florida
    Posts
    512
    Thanks
    9
    Thanked 61 Times in 59 Posts

    Default

    Omfg thanks i feel stupid xD
    Glad i posted the whole thing and thanks again for your help.
    -DW [Deadweight]
    Resolving your thread: First Post: => EDIT => Lower right: => GO ADVANCED => Top Advance Editor drop down: => PREFIX:Resolved

Similar Threads

  1. Replies: 1
    Last Post: 01-28-2011, 03:39 AM
  2. URL Dynamic value passing error
    By avirup in forum PHP
    Replies: 1
    Last Post: 09-22-2008, 03:39 AM
  3. Passing PHP through to JS
    By at.varley in forum PHP
    Replies: 2
    Last Post: 09-20-2007, 04:40 PM
  4. Error when passing special characters?
    By Mistrel in forum PHP
    Replies: 0
    Last Post: 12-03-2006, 06:03 PM
  5. Help In Passing A Value
    By NGJ in forum HTML
    Replies: 18
    Last Post: 06-01-2006, 04:47 PM

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
  •