Reputation: 15
I try simple thing , add number to var , for example :
<script>
function pag(id)
{
var valur=(id+1);
alert(""+valur);
}
</script>
<a href="javascript:pag('1');">More</a>
Always i get 1 and 1 no 2 , 3 , etc , anc continue , which the problem in this ?
Thank´s for the help
Upvotes: 0
Views: 31
Reputation: 59323
Your first problem is that you're calling the function with a string, not a number. '1' + 1
is '11'
, but 1 + 1
is 2.
Your second problem is that you're not saving the new value anywhere; you just keep calling the function with 1
. You need to use a variable.
Here's the fixed code:
<script>
var valur = 1;
function pag()
{
++valur; // add one
alert(valur);
}
</script>
<a href="javascript:pag();">More</a>
Upvotes: 3