I've only started learning Javascript for a few hours, and am trying to use a function to add to a variable using JS within HTML (Sorry if I used the wrong terminology) and it doesn't seem to be changing the result.
<html>
<head>
<title>TODO supply a title</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script>
var userID = 1;
var userRep = 0;
function NumUp(userRep) {
userRep = userRep + 1;
}
function NumDown(userRep) {
userRep = userRep - 1;
}
function myFunction() {
document.getElementById("demo").innerHTML = userRep;
}
</script>
</head>
<body>
<form action="Reputation.JS">
<div class="container">
<p>result goes here</p>
<button type="button" onclick="NumUp()" id="voteUp">Vote Up</button>
<button type="button" onclick="NumDown()" id="voteDown">Vote Down</button>
<label id="lbl"></label>
<button onclick="myFunction()">Click me</button>
<p id="demo"></p>
</div>
</form>
</body>
</html>
Much thanks for any help you can give.
I hope this will help. Thank you.
<html>
<head>
<title>TODO supply a title</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script>
var userID = 1;
var userRep = 0;
function NumUp(){
userRep = userRep + 1;
myFunction();
}
function NumDown(){
userRep = userRep - 1;
myFunction();
}
function myFunction() {
document.getElementById("demo").innerHTML = userRep;
}
</script>
</head>
<body>
<form action="Reputation.JS">
<div class="container">
<p>result goes here</p>
<button type ="button" onclick="NumUp()" id="voteUp">Vote Up</button>
<button type ="button" onclick="NumDown()" id="voteDown">Vote Down</button>
<label id="lbl"></label>
<button onclick="myFunction()">Click me</button>
<p id="demo"></p>
</div>
</form>
</body>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With