CrB írta:
Nem ez a kód nem fogja elmenteni. A javascript egy kliens oldali programozasi nyelv igy minden ami az oldalon történik a kliens gépén fut le. Ahhoz hogy a kattintasokat el tudd menteni szerver oldali prog nyelvre van szükség ilyen pl a PHP, ezen kívül a szerveren is kell tárolnod ehhez vagy fájlt vagy adatbázist használhatsz.
Egy ilyen kódot tudnál küldeni? Vagy hol találok ilyet, amit ki tudok íratni
html-re, pl arra amit én küldtem?
Az én esetemben arra csatolni azt, amit te írtál, ahhoz amit én küldtem.
Szerkesztve:Találtam egy kódot, ez nem tudom, hogy olyan lenne [profil]CrB[/profil]?
HTML:<html>
<head>
<script type="text/javascript">
function getVote(int)
{
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("poll").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","poll_vote.php?vote="+int,true);
xmlhttp.send();
if(typeof(Storage)!=="undefined")
{
if (localStorage.clickcount)
{
localStorage.clickcount=Number(localStorage.clickcount)+1;
}
else
{
localStorage.clickcount=1;
}
document.getElementById("result").innerHTML="You have voted " + localStorage.clickcount + " times before this session";
}
else
{
document.getElementById("result").innerHTML="Sorry, your browser does not support web storage...";
}
}
</script>
</head>
<body bgcolor=#5D003D>
<div id="poll">
<p>Click the button to see the counter increase.</p>
<p>Close the browser tab (or window), and try again, and the counter will continue to count (is not reset).</p><form>
<input type="Button" class="voteButton" name="vote" value="Vote" onclick="getVote(this.value)" />
</form>
</div>
</body>
</html>
PHP:<?php
$vote = $_REQUEST['vote'];
//get content of textfile
$filename = "poll_result.txt";
$content = file($filename);
//put content in array
$array = explode("||", $content[0]);
$yes = $array[0];
$no = $array[1];
if ($vote == 0)
{
$yes = $yes + 1;
}
if ($vote == 1)
{
$no = $no + 1;
}
//insert votes to txt file
$insertvote = $yes;
$fp = fopen($filename,"w");
fputs($fp,$insertvote);
fclose($fp);
?>
<table>
<tr>
<td><div id="votesMsg">Total Votes :</div></td>
<td><div id="votesCounter">
<?php echo($yes); ?></div>
</td>
</tr>
</table>
<input type="Button" class="voteButton" name="vote" value="Vote again !!!" onclick="getVote(this.value)" />