Append the last segment of the current url on button click
I have
a btn
<button id="next" onclick="inlastSegment()">Next</button>
and url
http://localhost:8888/projects/oop/2
My goal
when i clicked on this btn i want to increase it.
Example
-
http://localhost:8888/projects/oop/3
-
http://localhost:8888/projects/oop/4
-
http://localhost:8888/projects/oop/5
I tried
<script type="text/javascript">
var href = location.href; // http://localhost:8888/projects/oop/2
var lastSegment = window.location.pathname.split('/').pop();
console.log(lastSegment); //2
function inlastSegment() {
lastSegment = (parseInt(lastSegment)+1);
console.log(lastSegment); //3
//Stuck
}
</script>
I'm a bit stuck, any hints / suggestions would be much appreciated.
Is it possible to do this in PHP? Just out of curiosity.
+3
source to share