Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    New to the CF scene
    Join Date
    Dec 2012
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts

    I broke my simple javascript, help?

    I had a working script, made a few changes in attempts to cap the count page could go up to... Then somewhere I screwed it up and now my pageUp function no longer works. The function should section the URL to remove everything after #, up the page count, if the page count exceeds a certain point it does not load the next page. For whatever reason now it just doesn't work. It seems like the page number is not increasing. help?

    Code:
    // JavaScript Document
            var page = 0;
    	var url2 = "";
    	var url = window.location.toString();
    
    // Page jump function, limit chapter by pages
    
       	function pageUp() {
    		url2 = url.split('#')[0];
    		page = page + 1;
    		if (page <= 5) 
    		{
    			window.location.href = url2 + '#a' + page;
    		}
       	}

  • #2
    Senior Coder
    Join Date
    Apr 2011
    Location
    London, England
    Posts
    2,120
    Thanks
    15
    Thanked 354 Times in 353 Posts
    When you attempt to pageUp what appears in the address bar?

    Are there errors in your browser console?

    I assume the 'a' in '#a' is correct.
    "I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
    Validate your HTML and CSS

  • #3
    New to the CF scene
    Join Date
    Dec 2012
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts
    It basically acts as a non functioning function. Its a onclick button and there is no change in the url bar.

    and yes, the a is correct. It's basically intended to create url#a(x) in the url bar. And x being the page variable.

  • #4
    Senior Coder Logic Ali's Avatar
    Join Date
    Sep 2010
    Location
    London
    Posts
    1,028
    Thanks
    0
    Thanked 207 Times in 202 Posts
    When placed into a bare-bones page, your code works:

    Code:
    <doctype html>
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
    <body>
    <form action='#'>
     <input type='button' onclick='pageUp()' value='Change'>
    </form>
    
    <script type='text/javascript'>
    
    var page = 0;
    var url2 = "";
    var url = window.location.toString();
    
    function pageUp() {
      url2 = url.split('#')[0];
      page = page + 1;
      if (page <= 5) 
      {
       window.location.href = url2 + '#a' + page;
      }
    }
    
    </script>
    </body>
    </html>
    This suggests that the function isn't being called.

    You were asked to check the error console.

  • #5
    New to the CF scene
    Join Date
    Dec 2012
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts
    I apologize, I'm not familiar with what the error console is. I'm new to this , and the and learning.

    What would be causing the function not to call? I have a separate .js file that I link to and the call is
    Code:
    <img src="../images/misc/leftArrow.png" height="16" width="38" onclick="pageUp()">

  • #6
    Senior Coder Logic Ali's Avatar
    Join Date
    Sep 2010
    Location
    London
    Posts
    1,028
    Thanks
    0
    Thanked 207 Times in 202 Posts
    Quote Originally Posted by Christopher7xii View Post
    I apologize, I'm not familiar with what the error console is. I'm new to this , and the and learning.
    In Firefox press Ctrl + Shift + J

    Press "Clear"

    Click the image

    Check the console for error messages.
    ----------------------------------------

    Is that image enclosed by an a <A> tag ?

  • Users who have thanked Logic Ali for this post:

    Christopher7xii (12-10-2012)

  • #7
    New to the CF scene
    Join Date
    Dec 2012
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Logic Ali View Post
    In Firefox press Ctrl + Shift + J

    Is that image enclosed by an a <A> tag ?
    No... and apparently as I'm looking around I realize this is an issue.

    I just have the onclick in the <img> tag.

  • #8
    Senior Coder Logic Ali's Avatar
    Join Date
    Sep 2010
    Location
    London
    Posts
    1,028
    Thanks
    0
    Thanked 207 Times in 202 Posts
    Quote Originally Posted by Christopher7xii View Post
    No... and apparently as I'm looking around I realize this is an issue.

    I just have the onclick in the <img> tag.
    This is the point at which you post a live URL of a demo page.


  •  

    Posting Permissions

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