Send javaScript score from a game to PHP using hidden form - i dont get any value? -
hello want send score game(js) php can later store in database. dont value when click submit button save score. using hidden form.
as can see have tabel xwon, xlose, , on... when play game evertthing works , score js posted in tabel. when hit submit button dont values when use echo in top of code..? here html code
<?php if(isset($_post['xwon_score']) && isset($_post['xlose_score']) && isset($_post['drawgame_score']) && isset($_post['totalgames_score'])) { $xwon_score = $_post['xwon_score']; $xlose_score = $_post['xlose_score']; $drawgame_score = $_post['drawgame_score']; $totalgames_score = $_post['totalgames_score']; echo $xwon_score . $xlose_score . $drawgame_score . $totalgames_score; }else echo "testing......"; ?> <!doctype html> <html> <head> <script src="scripts/game.js"></script> <link type="text/css" rel="stylesheet" href="styles/general.css"> </head> <body onload="startgame();"> <table border="1" align="center"> <tr> <td>x won</td> <td>x lose</td> <td>draw</td> <td>total games</td> </tr> <tr> <td id="xwon_score">0</td> <td id="xlose_score">0</td> <td id="drawgame_score">0</td> <td id="totalgames_score">0</td> </tr> </table> </div> <div id="button_div"> <br> <button id="button" type="button" onclick="alert('restarting game')"><a href="javascript:startgame();">new game</a></button> <!-- problem section ????? --> <form method="post" action="game.php"> <input type="hidden" value="" id="won_score" name="xwon_score"/> <input type="hidden" value="" id="lose_score" name="xlose_score"/> <input type="hidden" value="" id="draw_score" name="drawgame_score"/> <input type="hidden" value="" id="total_score" name="totalgames_score"/> <!-- save highscore button --> <button type="submit" onclick="alert('saving highscore')">save highscore</button> </form>
and here function print js score:
function recordwin(winner){ if (winner == "x"){ xwon++; totalgames++; }else if (winner == "o"){ xlose++; totalgames++; }else if (winner ==""){ drawgame++; totalgames++; }savestats(); } function savestats(recordwin){ document.getelementbyid("xwon_score").innertext = xwon; document.getelementbyid("xlose_score").innertext = xlose; document.getelementbyid("drawgame_score").innertext = drawgame; document.getelementbyid("totalgames_score").innertext = totalgames; // somthing wrong here? document.getelementbyid("won_score").value = xwon; document.getelementbyid("lose_score").value = xlose; document.getelementbyid("draw_score").value = drawgame; document.getelementbyid("total_score").value = totalgames; }
the correct syntax this:
document.getelementbyid("myinput").value;
http://www.w3schools.com/jsref/prop_hidden_value.asp
document.getelementbyid("won_score").value = xwon; document.getelementbyid("lose_score").value = xlose; document.getelementbyid("draw_score").value = drawgame; document.getelementbyid("total_score").value = totalgames;
Comments
Post a Comment