Note: This code works on ALL the browsers BESIDES Firefox, and yes, I'm using the latest version.
Note: Im only including the code that is having issues, everything else works fine.
When I programmed the code below, Firefox would load everything else just fine.
The browser would accept the first button-function (a function called by a button), but not accept the 2nd or 3rd button-function.
The "Deal" button not included in the code I am presenting to you works fine. It prints a new page.
Now when the new page is printed, the "Hit" and "Stand" buttons appear. The problem is...
...the buttons will not print a new page like the "Deal" button did.
I belive the problem is either the defining of the function(s), or the content inside of them.
//**** STAND FUNCTION START DEALS DEALER CARDS ****
function stand()
/*Altough we have a "printCards" function, we will print the cards
differently in the stand function. Why? When the first cards are printed,
we have a hidden one, thus showing the hidden card in this function*/
{
dealerAcesTotal = dealerTotal;
if (dealerAcesTotal == 22){(dealerAcesTotal = 12);}
//KEEP DEALING CARDS TO THE DEALER WHILE THE HAND IS UNDER 17
while (dealerAcesTotal < 17)
{
randA = Math.floor((Math.random()*52)+1);//for the dealer
dealerCards[dealerHits] = card[randA];
dealerTotal = (dealerTotal + dealerCards[dealerHits][3]);
if (dealerCards[dealerHits][3] == 11){dealerAces = (dealerAces + 1);}
dealerHits = (dealerHits + 1);
dealerAcesTotal = dealerTotal;
}
//end of KEEP DEALING CARDS TO THE DEALER
//add a new row for totals and DEAL button
document.write("</TR><TR><TD align=center><FONT color=white><kbd>Dealer = " + dealerAcesTotal + "</TD>");
document.write("<TD align=center><FONT color=white><kbd>Player = " + playerAcesTotal + "</TD>");
document.write("<TD align=center><FONT color=white><kbd>BET = $" + bet + "</TD>");
document.write("<TD align=center><FONT color=white><kbd>" + handText + "<BR>"+ name +"'s Bank: $" + currentBank + "</TD>");
document.write("<TD align=center><FONT color=white><kbd><button onclick=\"\dealCards \(\)\">Deal</button></TD>");
document.write("</TR><TR>");
//****END OF PRINT CARDS TO FINISH HAND SCREEN
document.close();
return;
}
//**END OF STAND FUNCTION**
function hitMe(){playerHit();} //a sort of test for the browser...
//****PLAYER HITS FOR A NEW CARD****
function playerHit()
{
randA = Math.floor((Math.random()*52)+1);//for the player
playerCards[playerHits] = card[randA];
playerTotal = (playerTotal + playerCards[playerHits][3]);
if (playerCards[playerHits][3] == 11){playerAces = (playerAces + 1);}
playerHits = (playerHits + 1);
playerAcesTotal = playerTotal;
// run a loop for as many aces in the hand
//if the playerTotal is over 21 deduc
for (i = 0; i< playerAces; i++)
{
if ( playerAcesTotal > 21){playerAcesTotal = (playerAcesTotal - 10);}
}
printCards();
//document.close();
//return;
}
Feedback would be REALLY appreciated. :)
PS: My script is on the current page: http://ca1k.xkotto.com/portfolio/BLACKJACKV10.html
hitme and stand wont work in firefox because those functions are undefined when you call them.
This is because your printCards()
(and really all of your functions) incorrectly use document.write
. Other browsers like chrome are forgiving and will let you get away with this but in firefox when you do this you are overwriting the information that was previously on the page (including the javascript code itself).
You'll need to change all of your document.write
usages to use DOM functions instead like document.getElementById('mydiv').innerHTML += '<td>My New Card</td>'
and your document.clear
would be document.getElementById('mydiv').innerHTML ='';
Your probably going to have to tweak your styling to work with these changes also.