Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 12-10-2012, 12:46 AM   PM User | #1
Christopher7xii
New to the CF scene

 
Join Date: Dec 2012
Posts: 4
Thanks: 1
Thanked 0 Times in 0 Posts
Christopher7xii is an unknown quantity at this point
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;
		}
   	}
Christopher7xii is offline   Reply With Quote
Old 12-10-2012, 01:27 AM   PM User | #2
AndrewGSW
Senior Coder

 
Join Date: Apr 2011
Location: London, England
Posts: 2,120
Thanks: 15
Thanked 354 Times in 353 Posts
AndrewGSW will become famous soon enough
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
AndrewGSW is offline   Reply With Quote
Old 12-10-2012, 02:37 AM   PM User | #3
Christopher7xii
New to the CF scene

 
Join Date: Dec 2012
Posts: 4
Thanks: 1
Thanked 0 Times in 0 Posts
Christopher7xii is an unknown quantity at this point
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.
Christopher7xii is offline   Reply With Quote
Old 12-10-2012, 03:11 AM   PM User | #4
Logic Ali
Regular Coder

 
Logic Ali's Avatar
 
Join Date: Sep 2010
Location: London
Posts: 959
Thanks: 0
Thanked 198 Times in 193 Posts
Logic Ali will become famous soon enoughLogic Ali will become famous soon enough
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.
Logic Ali is offline   Reply With Quote
Old 12-10-2012, 03:24 AM   PM User | #5
Christopher7xii
New to the CF scene

 
Join Date: Dec 2012
Posts: 4
Thanks: 1
Thanked 0 Times in 0 Posts
Christopher7xii is an unknown quantity at this point
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()">
Christopher7xii is offline   Reply With Quote
Old 12-10-2012, 03:43 AM   PM User | #6
Logic Ali
Regular Coder

 
Logic Ali's Avatar
 
Join Date: Sep 2010
Location: London
Posts: 959
Thanks: 0
Thanked 198 Times in 193 Posts
Logic Ali will become famous soon enoughLogic Ali will become famous soon enough
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 ?
Logic Ali is offline   Reply With Quote
Users who have thanked Logic Ali for this post:
Christopher7xii (12-10-2012)
Old 12-10-2012, 04:14 AM   PM User | #7
Christopher7xii
New to the CF scene

 
Join Date: Dec 2012
Posts: 4
Thanks: 1
Thanked 0 Times in 0 Posts
Christopher7xii is an unknown quantity at this point
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.
Christopher7xii is offline   Reply With Quote
Old 12-10-2012, 10:58 AM   PM User | #8
Logic Ali
Regular Coder

 
Logic Ali's Avatar
 
Join Date: Sep 2010
Location: London
Posts: 959
Thanks: 0
Thanked 198 Times in 193 Posts
Logic Ali will become famous soon enoughLogic Ali will become famous soon enough
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.
Logic Ali is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 01:48 AM.


Advertisement
Log in to turn off these ads.