I want to have multiple buttons use the same function. Here What I'm trying to do.
<button><a herf="#" onClick="myFunction('clk1',c1);">button</a></button>
<p id="clk1"></p>
With the buttons I want to change the variable and change the paragraph
<script>
var c1 = 0;
function myFunction(paragraph,varibl) {
varibl += 1;
document.getElementById(paragraph).innerHTML = varibl;
}
</script>
I've looked around and can't find any thing. this doesn't work and I don't know how to make it work.
the full code:
<!DOCTYPE html>
<html>
<meta charset="utf-8"/>
<head>
<title>clicker clicker</title>
<style>
html {
text-align: center;
background-color: #d1d1d1;
font-family:Verdana;
}
.onebutton {
background-color: #f4f4f4;
border: 2px solid #5b5b5b;
color: #5b5b5b;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 32px;
cursor: pointer;
border-radius: 8px;
box-shadow:inset 0px 12px 22px 2px #ffffff;
}
.onebutton:active {
background-color: #e5e5e5;
}
.twobutton {
background-color: #f4f4f4;
border: 2px solid #5b5b5b;
color: #5b5b5b;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
cursor: pointer;
border-radius: 8px;
box-shadow:inset 0px 12px 22px 2px #ffffff;
}
.twobutton:active {
background-color: #e5e5e5;
}
</style>
</head>
<body>
<h1>Clicker Clicker</h1>
<p id="number"></p>
<button class="onebutton"><a herf="#" onClick="clc();">click</a>
</button>
<br>
<p>clicker:100</p>
<button class="twobutton"><a herf="#"
onClick="upgrade('clk1',c1);">buy</a></button>
<p id="clk1"></p>
<p>clicker:1000</p>
<button class="twobutton"><a herf="#" onClick="upgrade('clk2',c2);">buy</a></button>
<p id="clk2"></p>
<script>
var number = 0;
var c1 = 0;
var c2 = 0;
document.getElementById("number").innerHTML = number;
function clc() {
number += 1;
document.getElementById("number").innerHTML = number;
}
function update() {
number += c1;
document.getElementById("number").innerHTML = number;
c1 += c2;
document.getElementById("clk1").innerHTML = c1;
}
function upgrade(what,clicker) {
window[clicker] += 1;
document.getElementById(what).innerHTML = clicker;
}
setInterval(update, 100);
</script>
</body>
</html>
this is here so it doesnt say i have to much code sdljnvaksjdnfblkajsdbfjmas dbfmha bsdmnfb admsf bds msadf