I am trying to run this function set_downloads($file[0]); when the download button is clicked, i can’t just add it in the code, as it will run. I can put it on a different page and do some sort of onclick event to load it, but i don’t know how to do this.
<script type="text/javascript">
var x = 0;
var r = 0;
function countdown() {
if (x > 1) {
x--;
document.getElementById("button").innerHTML = x;
r = setTimeout("countdown()",0);
}
else {
clearTimeout(r);
document.getElementById("button").innerHTML = "Click to download (<?php echo $filesize;?>) ";
document.getElementById("button").disabled = "";
document.getElementById("button").onclick = function() {
document.getElementById("button").disabled = "disabled";
document.getElementById("button").innerHTML = "Your download is starting..";
};
}
}
setTimeout("countdown()",1000);
</script>
</head>
<body>
<label>
<font size="5"></font>
</label>
<a href="http://IP/uploads/<?php echo $fullfile; ?>" >
<button class="btn large orange" id="button" disabled="disabled">Click to download (<?php echo $filesize;?>) </button>
</a>
This event handler is what you want to use to handle events. It uses a callback, which calls that function argument after the button is clicked.
The other thing is, I’m not sure about your $file[0] variable, or where your set_downloads function is defined. where do you set these?