Forum Moderators: open
I've hunted the web for a good pagination script and come across what [i]may[i] be a cracker but I'm having some problems in implementing it. Take the code below:
var pageCurrent = 1;
var objPage = null;
function writePageControls() {
document.writeln (’<div class="toolBar">’);
document.writeln (’<div class="pagination">’);
Problem ONE: Firefox states that line 4 contains an "illegal character." Really? Where? After comparing several examples online I can't find out where.
Problem TWO is with the following code below:
<script type="text/javascript" language="javascript">
writePageControls();
</script>
Firefox claims this function is "undefined". Could somebody please point out what that means.
I'm admittedly new to Javascript and I'm working hard to try and implement a pagination script for a very long article. This script was originally taken from:
[peachpit.com...]
The article is great but contains a few typos and the above issues that I'm working through. Any help really appreciated.
Thanks alot
Stephen
document.writeln (’<div class="toolBar">’);
document.writeln (’<div class="pagination">’);
Should read:
document.writeln ('<div class="toolBar">');
document.writeln ('<div class="pagination">'); The article you've copied the code from has used the wrong character (may be for visual effect; I don't know?!) - they've used the closing single quote, whereas it should be the apostrophe. Unfortunately, if you simply copy & paste their code, it won't work!
Firefox claims this function is "undefined".
It simply can't find the function. This may be due to the above syntax errors - as the JavaScript could not be parsed correctly. Usually though this would be because the function is not defined in the current page (head section), or included (if in an external file).
[code-bin.homedns.org...]
Javascript is very new to me (though seems straightforward), but I'd be interested in your opinion to improve the script.
The original article is linked above
How would you alter the script then exactly?
As for this example, though, I would remove any script that was embedded inside the HTML content. For example:
<script type="text/javascript" language="javascript">
writePageControls();
</script>
Instead, do something like this in your <head> or right before the closing </body> tag:
<script type="text/javascript">
window.onload = function() {
writePageControls();
};
</script>
Your writePageControls method should then generate a bunch of elements and insert them into the DOM using methods like document.createElement, document.createTextNode, and appendChild. See the DOM Core spec:
[w3.org...]
or the HTML DOM tutorial at w3schools.com:
[w3schools.com...]
By moving your javascript out of your HTML content, it will be easier to maintain. Keep your content and behavior separated.