1

I am trying to move between pages, but when I try to go to the next page it does not work as expected. When I click it the first time the result is 01 instead of 1, and the second time it becomes 011 instead of 2. What am I doing wrong?

HTML:

<p id='page'>0</p>
<div id='pics'>
    <a href='<?=URL;?>index.php?p=gallery&image=<?=$pic['album_pic_id'];?>'>
        <img class='<?php if($pic['album_pic_id'] == $image) 
            { echo "selected_pic"; } ?>' width='90px' height='60px'
            src='<?=URL;?>images/albums/<?=$pic['album_pic_photo'];?>' />
     </a>
     <a onclick='getElementById("page").value = getElementById("page").value+1;'>
         Pievienot
     </a>
 </div>

Javascript:

window.onload = function() {
    var page = 0;
};
3
  • Are you trying to obfuscate your code? Commented Aug 29, 2012 at 0:23
  • The problem you describe and the code you show don't match up. That code won't ever result in 01 or 011 being displayed. Commented Aug 29, 2012 at 0:38
  • You should be using a span or button for the A element with the click listener. Commented Aug 29, 2012 at 0:40

1 Answer 1

4

Use innerHTML and parse its content to an integer with parseInt:

<a onclick='getElementById("page").innerHTML = parseInt(getElementById("page").innerHTML) + 1;'>Pievienot</a>

value only works with form elements such as input.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.