gamesmstr Posted January 19, 2009 Share Posted January 19, 2009 I am writing a blackjack game for my website and I am having difficulties submitting the bet form. The value of the bet is not available after the ajax submission. I have tried a myriad of formats, but no luck. Any help would be appreciated. Here is the launching file "cas_bj.php <?php session_start(); include("gameconfig.php"); $title = "Immortalix Casino - Blackjack"; if(!$email || !$password){ error("field"); exit; } if($playerinfo[jailtime] > 0){ error("jail"); exit; } if($playerinfo[password] != $password){ error("password"); } else{ include("include/inc-top-ajax.php"); echo('<script type="text/javascript" src="js/ajax-cas-bj.js"></script>'); $bet=0; $gold=$playerinfo[gold]; ?> <center> <div id="casinobox" class="casinobox"> <table width="649" height="449" border="1" cellpadding="5"> <tr> <td width="100" align="center"><?php echo"$playerinfo[username]";?></td> <td><img src="images/cards/cardback.jpg"></td> </tr> <tr> <td width="100" align="center">Dealer</td> <td><img src="images/cards/cardback.jpg"></td> </tr> </table> </div> <br /> <div id="betbox" class="betbox"> <input type="button" value="Begin Game" onclick="javascript:formaction('begin',<?php echo"$bet"; ?>);" /> </div> </center> <?php } include("bottom.php"); ?> Here is the file "ajax-cas-bj.php" <?php session_start(); include("../gameconfig.php"); if(!$email || !$password){ error("field"); exit; } if($playerinfo[jailtime] > 0){ error("jail"); exit; } if($playerinfo[password] != $password){ error("password"); } else{ echo('<script type="text/javascript" src="../js/ajax-cas-bj.js"></script>'); $action=$_POST["action"]; $player=$_POST["player"]; $player2=$_POST["player2"]; $dealer=$_POST["dealer"]; $bet=$_POST["bet"]; $bet2=$_POST["bet2"]; $c="j"; $s="s"; if ($action == "begin"){ ?> <center> <form name="betform" action="javascript:formaction('placebet',bet); return false;"> <table> <tr> <?php echo"<td><input type=text id=bet width=5 value=$bet /></td>"; ?> <td><input type="submit" value="Submit Bet" /></td> </tr> </table> </form> </center> <?php } elseif($action == "placebet"){ echo"test $bet"; // if ($bet > $playerinfo[gold]){ } } ?> And finally my ajax code ajax-cas-bj.js function createXMLHttpRequest() { if (typeof XMLHttpRequest != 'undefined') { return new XMLHttpRequest(); } try { return new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try { return new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) {} } return false; } function blackjack(action,player,player2,dealer,bet,bet2) { var xmlHttp11_out = createXMLHttpRequest(); params = "action=" + action + "&player=" + player + "&player2=" + player2 + "&dealer=" + dealer + "&bet=" + bet + "&bet2=" + bet2; xmlHttp11_out.open("POST","ajax/ajax-cas-bj.php", true); xmlHttp11_out.setRequestHeader("Content-Type","application/x-www-form-urlencoded"); xmlHttp11_out.onreadystatechange = function() { if(xmlHttp11_out.readyState == 4 && xmlHttp11_out.status == 200) { document.getElementById("casinobox").innerHTML = xmlHttp11_out.responseText; refresh_stats(); } } xmlHttp11_out.send(params); } function refresh_stats() { var xmlHttp12_out = createXMLHttpRequest(); params = ''; xmlHttp12_out.open("POST","ajax/statsajax.php", true); xmlHttp12_out.setRequestHeader("Content-Type","application/x-www-form-urlencoded"); xmlHttp12_out.onreadystatechange = function() { if(xmlHttp12_out.readyState == 4 && xmlHttp12_out.status == 200) { var brokenstring = xmlHttp12_out.responseText.split("-@[-"); if ( brokenstring[0] == 'stats' ) { document.getElementById("statbox").innerHTML = brokenstring[1]; } } } xmlHttp12_out.send(params); } function formaction(action,bet) { var xmlHttp13_out = createXMLHttpRequest(); params = "action=" + action + "&bet=" + bet; xmlHttp13_out.open("POST","ajax/ajax-cas-bj.php", true); xmlHttp13_out.setRequestHeader("Content-Type","application/x-www-form-urlencoded"); xmlHttp13_out.onreadystatechange = function() { if(xmlHttp13_out.readyState == 4 && xmlHttp13_out.status == 200) { document.getElementById("betbox").innerHTML = xmlHttp13_out.responseText; refresh_stats(); } } xmlHttp13_out.send(params); } It launches fine, gives the bet form, but nothing happens on the submit bet action. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.